n=int(input())
a=[]
best_cnt=0
[a.append(int(input())) for _ in range(n)]
b = sorted(a)
if len(set(b))==1:
  best=better=b[-1]
else:
  best=list(set(b))[-1]
  better=list(set(b))[-2]
for i in range(n):
  if a[i]==best:
    best_cnt+=1
    
for i in range(n):
  if a[i] == best:
    if b_cnt==1:
      print(better)
    else:
      print(best)
  else:
    print(best)