#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;

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")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

fn main() {
    let n:u32 = read();
    let a:Vec<u32> = (0..n).map(|_| read()).collect();
    let mut b = a.clone();
    b.sort();
    b.reverse();

    let mut cnt:u32 = 0;
    let mut mx:u32 = 0;
    for i in 0..n {
        let i = i as usize;
        if mx < a[i] {cnt=1; mx=a[i];}
        else if mx == a[i] {cnt+=1; mx=a[i];}
    }
    dbg!(cnt,mx);
    for i in 0..n {
        let i = i as usize;
        dbg!(a[i], mx, cnt);
        if cnt > 1 {
            if a[i] == mx { println!("{}", a[i]) }
            else {println!("{}", mx)}
        } else {
            if a[i] == mx {println!("{}", b[1])}
            else {println!("{}", mx)}
        }
    }
}
