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

S = sorted(A)
MAXS = max(S)
count = S.count(max(S))

for i in range(N):
    if A[i] == MAXS:
        if count > 1:
            print(S[-1])
        else:
            print(S[-2])
    else:
        print(S[-1])

