n=int(input())
a=[int(input()) for i in range(n)]
b=list(set(a))
if len(b)==1:
  for i in range(n):
    print(b[0])
elif a.count(b[-1])>=2:
  for i in a:
    print(i)
else:
  for i in a:
    if i==b[-1]:
      print(b[-2])
    else:
      print(b[-1])
