N = int(input())
A = [int(input()) for i in range(N)]
tmp = max(A)
li = [i for i, x in enumerate(A) if x == tmp]
li2 = list(set(A))
li2.sort(reverse=True)
if len(li2)>1:
    tmp2 = li2[1]
elif len(li2) == 1:
    tmp2 = li2[0]
for i in range(N):
    if li.count(i)==0:
        print(tmp)
    else:
        print(tmp2)