import sys
def main():
    N = int(sys.stdin.readline())
    A = [int(sys.stdin.readline()) for i in range(N)]
    maxa = max(A)
    if A.count(maxa) > 1:
        for i in range(N):
            print(maxa)
    else:
        for i in range(N):
            if i != A.index(maxa):
                print(maxa)
            else:
                print(sorted(A)[-2])
                
main()