a = int(input())
b = [int(input()) for i in range(a)]
c = sorted(b)[-2]
if b.count(max(b)) >= 2:
  for i in range(a):
    print(max(b))
else:
  for i in b:
    if i == max(b):
      print(c)
    else:
      print(max(b))