use std::io::*;
use std::str::*;

fn read<T: FromStr>(s: &mut StdinLock) -> Option<T> {
    let s = s
        .by_ref()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main() {
    let stdin = std::io::stdin();
    let n = read::<u32>(&mut stdin.lock()).unwrap();

    let mut d = [0u32; 200000];
    for i in 0..n {
        unsafe {
            d[i as usize] = read::<u32>(&mut stdin.lock()).unwrap();
        }
    }

    d.sort();

    for i in 0..n {
        unsafe {
            if i == n - 2 {
                let iine = d.get_unchecked(199998);
                println!("{}", iine);
            } else {
                let iine = d.get_unchecked(199999);
                println!("{}", iine);
            }
        }
    }
}
