N=int(input())
A=[]
M1=[0]
M2=[0]

max_val = 0
for i in range(N):
    input_val = int(input())
    if (max_val < input_val):
        max_val = input_val
    A.append(input_val)
    if (i < N -1):
        M1.append(max_val)

max_val = 0
for i in range(N-1):
    input_val = A[N-1-i]
    if (max_val < input_val):
        max_val = input_val
    M2.append(max_val)

if (N<=2):
    print(A[0])
    print(A[1])
else:
    for i in range(N):
        print(max(M1[i], M2[N-1-i]))
