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

max_A = max(A)
Second = A.copy()
Second.remove(max(max_A))
second_A = max(Second)

max_index = [i for i, v in enumerate(A) if v == max_A]

answer = [max_A] * N
for i in max_index:
    answer[i] = second_A
for i in range(N):
    print(answer[i])