import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l=[int(input()) for i in range(n)]

    if len(set(l))==1:
        for i in range(n):
            print(max(l))
    else:
        biggest = max(l)
        niban=sorted(set(l))[-2]
        for j in range(n):
            if l[j]!=biggest:
                print(biggest)
            else:
                print(niban)
resolve()