n = int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())
b = sorted(a,reverse=True)
m = b[0]
if b[0] == b[1] and b[0] == m:
    for i in range(n):
        print(m)
else:
    for i in range(n):
        if a[i] == m:
            print(max(b[1:]))
        else:
            print(max(a))