n = int(input())
a = []
for i in range(n):
    ai = int(input())
    a.append(ai)


if(a.count(max(a)) >= 2):
    la = list(set(a))
    la = sorted(la, reverse=True)
    l1 = la[0]
    for i in range(n):
        print(l1)
else:
    for i in range(n):
        la = list(set(a))
        la = sorted(la, reverse=True)
        l1 = la[0]
        l2 = la[1]
        if(a[i] == l1):
            print(l2)
        else:
            print(l1)

