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

sA = sorted(A, reverse=True)
maxA,smaxA = sA[0:2]

for i in range(N):
    if A[i] != maxA:
        print(maxA)
    else:
        print(smaxA)