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

b=a.copy()
b=sorted(b, reverse=True)
print(b)

for i in range(n):
    if a[i] == b[0]:
        print(b[1])
    else:
        print(b[0])
