local mce, mfl, msq, mmi, mma = math.ceil, math.floor, math.sqrt, math.min, math.max
local n = io.read("*n")
local a, b = {}, {}
for i = 1, n do
  a[i] = io.read("*n")
  b[i] = a[i]
end
table.sort(b)
local m1, m2 = b[n], b[n - 1]
for i = 1, n do
  if a[i] == m1 then
    print(m2)
  else
    print(m1)
  end
end
