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]

one_max = (len(max_index) == 1)

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