N=int(input())
cnt=0
flg=0
max1=0
max2=0
for i in range(N):
    A=int(input())
    if A > max1:
        cnt = 0
        flg = 0
        if i == 0:
            max2 = A
        else:
            max2 = max1
        max1 = A
        maxi = i
    elif A == max1:
        cnt+=1
    if A > max2 and max1 > A :
        max2 = A
    if cnt > 1:
        flg = 1
if flg == 1:
    for i in range(N):
        print(max1)
elif max1 != max2:
    for i in range(N):
        if i != maxi:
            print(max1)
        else:
            print(max2)
else:
    for i in range(N):
        print(max1)
