n = int(input())
a = [int(input()) for _ in range(n)]
maxa = max(a)
if a.count(maxa) > 1:
    for i in range(n):
        print(max(a))
else:
    for j in range(n):
        if a[j] == maxa:
            sorta = sorted(a)
            print(sorta[-2])
        else:
            print(maxa)