N = int(input())
A = []
a = int(input())
M1 = a
M2 = a
A.append(a)
for i in range(N-1):
    a = int(input())
    A.append(a)
    M1 = max(M1,a)
    if M2 < a < M1:
        M2 = a

if A.count(M1) >= 2:
    for i in range(N):
        print(M1)
else:
    for i in range(N):
        if A[i] == M1:
            print(M2)
        else:
            print(M1)
            
