use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [usize; n]
    };

    let a: Vec<usize> = a;
    let max = a.iter().max().unwrap();

    for i in 0..n {
        if a[i] == *max {
            let mut x = a.clone();
            x[i] = 0;
            println!("{}", x.iter().max().unwrap());
        } else {
            println!("{}", max);
        };
    }
}
