N = int(input())
A = []
for i in range(N):
    A.append(input())
A_copy = A[:]
A_sort = sorted(A_copy)
# print(A, A_sort)

for i in range(N):
    if A[i] != A_sort[-1]:
        print(A_sort[-1])
    else:
        print(A_sort[-2])