n = int(input())
a = [int(input()) for i in range(n)]

# ほとんどは全体のmax?
m1 = max(a)

# max値が多い場合用に2nd max
a2 = list(set(a))
a2.remove(m1)
if len(a2) > 0:
  m2 = max(a2)
else:
  m2 = 0

if m2 != 0:
  for i in range(n):
    ai = a[i]
    if ai == m1:
      print(m2)
    else:
      print(m1)
else:
  for i in range(n):
    print(m1)