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)
m2 = max(a2)

for i in range(n):
  if a[i] == m1:
    print(m2)
  elif a[i] == m2:
    print(max(a[:i]+a[i+1:]))
  else:
    print(m1)