fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read2<T: std::str::FromStr>(n: u32) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let n: u32 = read();
    let a: Vec<i32> = read2(n);
    let mut first: (i32, i32) = (0, 0);
    let mut second: (i32, i32) = (0, 0);
    let mut count: i32 = 0;
    for elem in a.iter() {
        println!("elem: {}", *elem);
        if *elem > first.1 {
            second = first;
            first = (count, *elem);
        } else if *elem > second.1 {
            second = (count, *elem);
        }
        count += 1;
    }
    for i in 0..count {
        let result = match i == first.0 {
            true => second.1,
            false => first.1,
        };
        println!("{}", result);
    }
}