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

normal = max(A)
maxindex = [i for i, x in enumerate(A) if x == max(A)]
A.remove(normal)
exception = max(A)

for i in range(N):
    if i in maxindex:
        print(exception)
    else:
        print(normal)