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

s = [i for i, v in enumerate(a) if v == max(a)]
if len(s) >= 2:
     for i in range(n):
          print(max(a))
else:
     for i in range(n):
          if i == s[0]:
               print(sorted(a)[-2])
          else:
               print(max(a))