N = int(input())
A = []
for i in range(N):
        A.append(int(input()))
B = A.copy()
B.sort()
B.reverse()
print(B)
print(A)
for i in range(0,N):
        if A[i] == B[0]:
                print(B[1])
        else:
                print(B[0])
