#abc134c
import copy

n=int(raw_input())
a=[]
for i in xrange(n):
 a.append(int(raw_input()))
num1=sorted(a)[-1]
num2=sorted(a)[-2]
if a.count(num1)>1:
 for i in xrange(n):
  print num1
else:
 for i in xrange(n):
  if a[i]==num1:
   print num2
  else:
   print num1
