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

B = A.copy()
B.remove(max(A))
second_max = max(B)
for i in range(N):
    if A[i] == max(A):
        print(second_max)
    else:
        print(max(A))