N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))

if A[0] > A[1]:
    max_1, max_2 = A[0],A[1]
else:
    max_1, max_2 = A[1],A[0]

dict = {}
for i, a in enumerate(A):
    if a in dict:
        dict[a] += 1
    else:
        dict[a] = 1
    if i >= 2:
        if a > max_1:
            max_1 = a
            max_2 = max_1
        elif a > max_2:
            max_2 = a

for a in A:
    if a == max_1:
        if dict[a] >= 2:
            print(max_1)
        else:
            print(max_2)
    else:
        print(max_1)


