n=int(input())
imax=0
amax=int(input())
amax2=amax
for i in range(1,n):
    ai=int(input())
    if amax<ai:
        adummy=amax
        amax=ai
        imax=i
        amax2=adummy
    elif amax2<ai:
        amax2=ai
if imax==0:
    print(amax2)
    for i in range(1,n):
        print(amax)
elif imax==n-1:
    for i in range(n-1):
        print(amax)
    print(amax2)
else:
    for i in range(imax):
        print(amax)
    print(amax2)
    for i in range(n-imax-1):
        print(amax)
    
