n = int(input())
A = []

for i in range(n):
    A.append(int(input()))

if len(set(A)) == 1:
    for i in range(n):
        print(A[0])
else:
    A_ = sorted(set(A))
    max_1 = A_[-1]
    max_2 = A_[-2]
    for i in A:
        if i == max_1:
            print(max_2)
        else:
            print(max_1)
    