N=int(input())
A=[int(input()) for _ in range(N)]
tmp=A.copy()
tmp.sort(reverse=True)

Afirst=max(A)
if len(set(tmp))==1:
    Asecond=Afirst
else:
    for a in tmp:
        if a!=Afirst:
            Asecond=a
            break
for a in A:
    if a==Afirst:
        print(Asecond)
    else:
        print(Afirst)
