a=int(input())
b=[int(input()) for i in range(a)]
m=max(b) 

if b.count(m)>=2:
    for i in range(a):
        print (m)
else:
    b.sort(reverce=True)
    m2=b[1]
    for i in range(a):
        if b[i]==m:
            print(m2)
        else:
            print (m)
            
