import Collection

N = int(input())

a = []
for i in range(N):
  a.append() = int(input())
  
for j in range(N):
  if a[j] < max(a):
    print(max(a))
  elif a[j]==max(a):
    if max(a) == max(a[0:j-1]) or max(a) == max(a[j+1:N]):
      print(max(a))
    else:
      if max(a[0:j-1]) > max(a[j+1:N]):
      	print(max(a[0:j-1]))
      else:
     	print(max(a[j+1:N]))
  else:
    if max(a[0:j-1]) > max(a[j+1:N]):
      print(max(a[0:j-1]))
    else:
      print(max(a[j+1:N]))