n = gets.to_i

max = 0
second = 0
max_index = 0
n.times{|i|
    val = gets.to_i
    if val > max
        second = max
        max = val
        max_index = i
    else val > second
        second = val
    end
}

n.times{|i|
    puts i == max_index ? second : max
}