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

S = sorted(A)
MAXS = max(S)
two = S[-2]
# print("MAX {} two {}".format(MAXS,two))
count = S.count(max(S))

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

