n=int(input())
A=[int(input()) for i in range(n)]
B=sorted(set(A))[::-1]
if len(B)==1:
  for i in range(n):
    print(B[0])
else:
  for i in range(n):
    if A[i]==B[0]:
      print(B[1])
    else:
      print(B[0])