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

B = sorted(A, reverse=True)
max_first = B[0]
max_second = B[1]

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