n = int(input())
a = [input() for i in range(n)]
if a.count(max(a)) >= 2:
    for i in range(n):
        print(max(a))
else:
    b = a.copy()
    b.remove(max(b))
    c = max(b)
    for i in range(n):
        if a[i] == max(a):
            print(c)
        else:
            print(max(a))


