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

x = max(a)

b = sorted(list(set(a)), reverse=True)
if(len(b) == 1):
   y = x
else:
   y = b[1]

for i in range(n):
   if(a[i] < x):
      print(x)
   else:
      print(y)
