n=int(input())
a=[int(input()) for i in range(n)]
b=a.copy()
b.sort()
if b[-1]==b[-2]:
    for i in range(n):
        print(a[-1])
else:
    for i in range(n):
        if a[i]==b[-1]:
            print(b[-2])
        else:
            print(b[-1])