n=int(input())
a=[int(input()) for i in range(n)]
max1=sorted(a)[-1]
if sorted(a)[-2]!=max1:
    max=sorted(a)
    max2=0
    for i in range(2,n):
        if max[-i]!=max1:
            max2=max[-i]
            break
    for i in range(n):
        if a[i]==max1:
            print(max2)
        else:
            print(max1)
else:
    for i in range(n):
        print(max1)
