n = int(input())
a = [0]*n
for i in range(n):
  a[i] = int(input())

x = sorted(set(a), reverse = True)
t = [0]*2
if len(x) > 1:
  t[0],t[1] = x[0],x[1]
else:
  t[0],t[1] = x[0],x[0]
  
max = t[0]  
for i in range(n):
  if a[i] == max:
    if a.count(max) > 1:
      print(max)
    else:
      print(t[1])
  else:
    print(max)
  