N=int(input())
a=[]
for _ in range(N):
  a_=int(input())
  a.append(a_)
x=max(a)
b=a
if a.count(x)>=2:
  for i in range(N):
    print(x)
else:
  for i in range(N):
    if a[i]==x:
      b.sort()
      print(b[-2])
    else:print(x)