n = int(input())
l = [int(input()) for i in range(n)]
a = [0]
ma = 0
for i in range(len(l)):
    if l[i] > ma:
        ma = l[i]
    a.append(ma)
a.append(0)
b = [0]
ma = 0
for i in range(len(l)):
    if l[-i-1] > ma:
        ma = l[-i-1]
    b.insert(0,ma)
b.insert(0,0)
#print(a,b)
for i in range(n):
    print(max(a[i],b[i+2]))
