N = int(input())
if N == 2:
    print(input() for _ in range(2))
else:
    A = [input() for _ in range(N)]
    tmp = sorted(A)
    del tmp[0:(N-2)]
    for i in range(N):
        if A[i] == tmp[1]:
            print(tmp[0])
        else:
            print(tmp[1])