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

B = sorted(A, reverse=True)
max_first = B[0]
max_second = B[1]

for i in range(N):
    answer = max_first
    if A[i] == max_first:
        answer = max_second
    print(answer)
