n = int(input())
a = [int(input()) for i in range(n)]

b = sorted(a)

if b[-1]==b[-2]:
    for i in range(n):
        print(b[-1])
else:
    for i in range(n):
        if b[i]==a[-1]:
            print(b[-2])
        else:
            print(b[-1])
