n = gets.to_i
a = []
for i in 1..n do
  a[i] = gets.to_i
end
left = [0]
for i in 1..n do
  left[i] = [left[i - 1], a[i]].max
end
right = []
right[n + 1] = 0
for i in 1..n do
  right[n + 1 - i] = [right[n + 2 - i], a[n + 1 - i]].max
end
for i in 1..n do
  puts [left[i - 1], right[i + 1]].max
end
