use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let a: Vec<usize> = (0..n)
        .map(|_| iter.next().unwrap().parse().unwrap())
        .collect();
    let mut l = a.clone();
    let mut r = a.clone();
    for i in 1..n {
        l[i] = std::cmp::max(l[i], l[i - 1]);
    }
    for i in n - 1..0 {
        r[i] = std::cmp::max(r[i], r[i + 1]);
    }
    for i in 0..n {
        let mut ans = 0;
        if i >= 1 {
            ans = std::cmp::max(ans, l[i - 1]);
        }
        if i + 1 < n {
            ans = std::cmp::max(ans, r[i + 1]);
        }
        println!("{}", ans);
    }
}
