n,*a=map(int,open(0))
m=max(a)

if a.count(m)>1:
    for i in range(n):
        print(m)
else:
    s=sorted(set(a))[::-1][1]
    for i in a:
        if i==m:
            print(m)
        else:
            print(s)