N = int(input())

A = []
for i in range(N):
    x = input()
    A.append(x)

new_A = sorted(A, reverse=True)

for i in range(N):
    if A[i] == new_A[0]:
        print(new_A[1])
    else:
        print(new_A[0])
