use std::io::*;
use std::cmp;
use std::str::FromStr;

fn read<T: FromStr> () -> T {
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let N = read::<usize>();
    let mut vec: Vec<i64> = Vec::new();
    for _ in 0..N{
        vec.push(read::<i64>());
    }

    for i in 0..N {
        let max1 = match &vec[0..i].iter().max() {
            Some(&x) => x,
            None => -1,
        };
        let max2 = match &vec[(i+1)..N].iter().max() {
            Some(&x) => x,
            None => -1
        };
        println!("{}", std::cmp::max(max1, max2));
    }
}

