n = int(input())
L = list(int(input()) for i in range(n))

L_sorted = sorted(L, reverse = True)
print(L)
for i in L:
    max = L_sorted[0]
    if max == i:
        print(L_sorted[1])
    else:
        print(max)
