N = int(input())
A = [input() for i in range(N)]
maxA = max(A)
secA = sorted(set(A))[-2]
num=A.count(maxA)
#print(N,A,maxA,secA,num)

for i in range(N):
  if num>1:
    print(maxA)
  elif A[i]==maxA:
    print(secA)
  else:
    print(maxA)