N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
    
MAX1 = max(A)
MAX2 = -1
for i in range(N):
    if i != A.index(MAX1):
        MAX2 = max(MAX2,A[i])
        
if MAX1 == MAX2:
    for i in range(N):
        print(MAX1)
else:
    for i in range(N):
        if i == A.index(MAX1):
            print(MAX2)
        else:
            print(MAX1)
            
    