N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
max = max(A)
max2 = sorted(A)[-2]
print(A)
if max == max2:
    for i in A:
        print(max)
else:
    for i in A:
        if i == max:
            print(max2)
        else:
            print(max)