N=int(input())

seq=[]

for i in range(N):

    a= int(input())
    
    seq.append(a)

left=[0]
for i in range(N-1):
    left_i=max(left[i],seq[i])

    left.append(left_i)

right=[0]

for j in range(N-1):
    right_j = max(right[j],list(reversed(seq))[j])

    right.append(right_j)

right = list(reversed(right))

for k in range(N):
    print(max(left[k],right[k]))