N = int(input())
A = [int(input()) for _ in range(N)]
A_s = sorted(A)[::-1]
print(A_s)

for i in A:
    if (A_s[0] == i) & (A_s[1] == i):
        print(A_s[0])
    elif (A_s[0] == i) & (A_s[0] != A_s[1]):
        print(A_s[1])
    else:
        print(A_s[0])
