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

fn read<T: FromStr>() -> T {
    let stdin = 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: u64 = read();
    let mut a: Vec<(u64,u64)> = (0..n).map(|x| (read(),x)).collect();
 
    a.sort_by_key(|&x| Reverse(x));
    let max = a.iter().max();

    println!("{:?}",a);

    for i in 0..n {
        if i == max.unwrap().1 {
            println!("{}",a[1].0);
        } else {
            println!("{}",max.unwrap().0);
        }
    }
}