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

normal = max(A)
hoge = A.copy()
hoge.remove(normal)
exception = max(hoge)

for i in range(N):
    if A[i] == normal:
        print(exception)
    else:
        print(normal)