N=int(input())
A=[int(input()) for _ in range(N)]
tmp=sorted(A, reverse=True)

sA=list(set(tmp))
if len(sA)==1:
    firstA, secondA=sA[-1], sA[-1]
else:
    firstA=sA[-1]
    secondA=sA[-2]

for a in A:
    if a==firstA:
        print(secondA)
    else:
        print(firstA)
