use std::io::stdin;

fn main() {
    let mut n = String::new();
    stdin().read_line(&mut n).unwrap();
    let n: usize = n.trim().parse().unwrap();

    let mut l = [0; 200003];
    let mut r = [0; 200003];
    let array: Vec<usize> = (0..n).map(|_| {
        let mut a = String::new();
        stdin().read_line(&mut a).unwrap();
        a.trim().parse().unwrap()
    }).collect();
    for (i, &a) in array.iter().enumerate() {
        l[i + 1] = if a > l[i] { a } else { l[i] };
    }
    for (i, &a) in array.iter().rev().enumerate() {
        r[i + 1] = if a > l[i] { a } else { l[i] };
    }
    for i in 1..n+1 {
        let li = i - 1;
        let ri = n - i;
        println!("{}", if l[li] < r[ri] { r[ri] } else { l[li] });
    }
}
