N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
B = [max(A[: n+1]) for n in range(N)]
C = [max(A[N - n - 1:]) for n in range(N)][::-1]

for n in range(N):
    if n == 0:
        print(C[n+1])
    elif n == N - 1:
        print(B[n-1])
    else:
        print(max(B[n-1], C[n+1]))
