def solve():
    n=int(input())
    max1=0
    max2=0
    count=0
    num=[]
    def append(num1):
        num.append(num1)
    for i in range(n):
        a=int(input())
        if max1<a:
            count=1
            max2=max(max2,max1)
            max1=a
        elif max1==a:
            count+=1
        elif max2<a:
            max2=a
        append(a)
    if count!=1:
        for i in range(n):
            print(num[i])
    else:
        for i in range(n):
            if num[i]==max1:
                print(max2)
            else:
                print(max1)
solve()
