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

B = sorted(A)
A_max, A_second_max = B[-1], B[-2] 
for i in A:
    if i == A_max:
        print(A_second_max)
    else:
        print(A_max)