n = int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())
amax = sorted(a)[-2:]
print(amax)
for i in range(n):
    if a[i] == amax[1]:
        print(amax[0])
    else:
        print(amax[1])
