N=int(input())
AList = [int(input()) for i in range(N)]

if AList.count(max(AList)) > 1:
    for i in range(N):
        print(max(AList))
else:
    SList=sorted(AList)
    SecMax=SList[-2]
    MaxIndex=AList.index(max(AList))
    
    for i in range(N):
        if i==MaxIndex:
            print(SecMax)
        else:
            print(max(AList))
    
    
    
