N = int(input())
a=[]
for i in range(N):
  a.append(int(input()))

base=max(a)
maxkosu=a.count(base)
if maxkosu>1:
  for i in range(N):
    print(base)
else:
  maxidx=a.index(base)
  reigai=max(max(a[:maxidx]), max(a[maxidx+1:]))
  for i in range(N):
    if i==maxidx:
      print(reigai)
    else:
      print(base)
  