N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
max1 = max(A)
index = []
max2 = sorted(A)[1]
for i in range(N):
    if(A[i] == max1):
        print(max2)
    else:
        print(max1)