N = int(input())
A = []
for i in range(N):
    A.append(input())
A_copy = A[:]
A_copy.sort()
# print(A, A_sort)
A_max = A_copy[N-1]
A_second = A_copy[N-2]
for i in range(N):
    if A[i] != A_max:
        print(A_max)
    else:
        print(A_second)
