n = int(input())
a = [int(input()) for _ in range(n)]
a1 = sorted(a)
if a1[n-1]==a1[n-2]:
  flag = True ## true = have repeat
  maxone = a1[n-1]
else:
  flag = False ## false = no repeat
  maxone = a1[n-1]
  maxtwo = a1[n-2]
for i in range(n):
  if a[i]==1max and flag==True: print(maxone)
  elif a[i]==1max and flag==False: print(maxtwo)
  elif a[i]!=1max: print(maxone)
