import numpy as np
N = int(input())
A = np.array([int(input()) for i in range(N)])
ans = np.zeros(N, dtype=int)

ans[0] = A[1:].max()
ans[N-1] = A[:-1].max()

for i in range(1, N-1):
    left = A[:i].max()
    right = A[i+1:].max()
    ans[i] = max(left, right)

print(*ans, sep="\n")