let N = (Int)(readLine()!)!;
var maximum = 0;
var secondMaximum = 0;
var count: Array<Int> = Array(repeating: 0, count: 200020);
var A: Array<Int> = Array(repeating: 0, count: 200020);
for i in 0 ..< N {
    let a = (Int)(readLine()!)!;
    A[i] = a;
    if a > maximum {
        secondMaximum = maximum;
        maximum = a;
    }
    else if a > secondMaximum {
        secondMaximum = a;
    }
    count[a] += 1;
} 
for i in 0 ..< N {
    if A[i] != maximum {
        print(maximum);
    }
    else if A[i] == maximum && count[A[i]] == 1 {
        print(secondMaximum);
    }
    else {
        print(maximum);
    }
}