n = gets.to_i
a = Array.new(n) {
    gets.to_i
}

max = a.reduce([-1, -1]) {|acc, item|
    if item > acc[0] then
        [item, acc[0]]
    elsif item > acc[1] then
        [acc[0], item]
    else
        acc
    end
}

for i in 0...n do
    if max[0] != a[i] then
        puts max[0]
    else
        puts max[1]
    end
end
