N = int(input())
A = [int(input()) for i in range(N)]
B = sorted(A,reverse=True)
max1 = B[0]
max2 = B[1]
print(max1,max2)
for i in N:
    if A[i] == max1:
        print(max2)
    else:
        print(max1)