N = int(input())
A = [input() for i in range(N)]

A_sort = sorted(A)
A_max = A_sort[-1]
A_max2 = A_sort[-2]

for i in range(N):
    if A[i]==A_max:
        print(A_max2)
    else:
        print(A_max)