N = int(input())
A = [input() for _ in range(N)]
max_A = max(A)
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:
    Second = A.copy()
    Second.remove(max_A)
    Second_A = max(Second)
    for i in max_index:
        answer[i] = Second_A

for i in range(N):
    print(answer[i])