N=int(input())
max1=0
second_max=0
ind=[]
for i in range(N):
  t=int(input())
  if second_max <= t:
    if max1<t:
        max1=t
        ind.clear()
        ind.append(i)
    elif max1==t:
    	ind.append(i)
    else:
        second_max=t
if len(ind)==1:
    for i in range(N):
      if i in ind:
        print(second_max)
      else:
          print(max1)
else:
    for i in range(N):
          print(max1)
