n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
b = sorted(a)
m = b[n-2]
M = b[n-1]
if a[n-1] == a[n-2]:
  for i in range(n):
    print(a[n-2])
else:
  for i in range(n):
    if a[i] == M:
      print(m)
    else:
      print(M)