/// 1行の文字を空白で分割してVec<T>にする。
fn readone_multi<T : std::str::FromStr>(count : usize) -> Vec<T> {
    let mut v : Vec<T> = Vec::with_capacity(count);
    for _ in 0..count {
        let mut input = String::new();
        std::io::stdin().read_line(&mut input).unwrap();
        v.push(input.trim().parse().ok().unwrap());
    }
    v
}

fn main() {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    let input : usize = input.trim().parse().ok().unwrap();
    let input = input;
    let vec : Vec<i32> = readone_multi(input);
    let mut max = -1;
    let mut maxcount : usize = 0;
    let mut maxlength = 0;
    let mut second = -1;
    for i in 0..input {
        if vec[i] > max {
            max = vec[i];
            maxcount = i;
            maxlength = 1;
            continue;
        }
        if vec[i] == max {
            maxlength += 1;
            continue;
        } 
        if vec[i] > second {
            second = vec[i];
        }
    }
    if maxlength > 1 {
        for _ in 0..input {
            println!("{}", max)
        }
        return;
    }
    for i in 0..input {
        if i == maxcount {
            println!("{}", second);
            continue;
        }
        println!("{}", max)
    }
}

