N = int(input())
A = []
for i in range(N):
    A.append(input())
    
A_sorted = sorted(A)
A_max1 = A_sorted[-1]
A_max2 = A_sorted[-2]

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