n = int(input())
aMax=0
multi=0
a = [0 for i in range(n)]
for i in range(n):
  a[i] = int(input())
  if aMax == a[i]:
    multi = 1
  elif aMax < a[i]:
    aMax = a[i]
    multi = 0

if multi == 1:
  for i in range(n):
    print(aMax)
else:
  for i in range(n):
    if aMax != a[i]:
      print(aMax)
    else:
      if i == 0:
        aMax1=max(a[1:n])
        print(aMax1)
      else:
        aMax2=max(a[0:i],a[i+1:n])
        print(aMax2[0])  
