N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
else:
    MAX = max(A)

for i in range(N):
    if MAX != A[i]:
        print(MAX)
        continue
    if i > 1 and i < N - 2:
        print(max(A[:i]),max(A[i+1:]))
        continue
    if i == 0:
        print(max(A[1:]))
        continue
    if i == 1 and N == 2:
        print(A[0])
        continue
    if i == 1 and N > 2:
        print(max(A[0], max(A[2:])))
        continue
    if i == N -2:
        print(max(max(A[:N-2]), A[N-1]))
        continue
    if i == N - 1:
        print(max(A[:N-1]))
    