n=int(input())
for _ in range(n):
  a.append(int(input()))
l=[l[0]]*n
for i in range(1,n):
  l[i] = max(a[i],l[i-1])
a.reverse()
r=[r[0]]*n
for i in range(1,n):
  r[i] = max(a[i],r[i-1])
for i in range(n):
  print(max(l[i-1],r[n-i-1]))

 