import copy
n=int(input())
l=[int(input()) for _ in range(n)]


k=sorted(l)
dic_lst={}
for i in l:
  if i not in dic_lst:
    dic_lst[i]=1
  else:
    dic_lst[i]+=1
for i in l:
  max_num=max(dic_lst.keys())
  if i<max_num:
    print(max_num)
  if i==max_num:
    if dic_lst[i]>1:
      print(max_num)
    elif dic_lst[i]==1:
      print(k[-2])
