n = int(input())
num = []
maxnum = 0
count = 1
for i in range(n):
  a = int(input())
  if a!=maxnum:
    maxnum = max(maxnum,a)
  else:
    count += 1
  num.append(a)
  
for i in range(n):
  if count>1:
    print(maxnum)
  else:
    if num[i]!=maxnum:
      print(maxnum)
    else:
      subnum = num[0:i] + num[i+1:n]
      subnum = sorted(subnum)
      print(subnum[n-2])