n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
max1 = 0
for j in a:
    if j > max1:
        max1 = j
min1 = 2000001
for t in a:
    if t < min1:
        min1 = t
max2 = 0
for e in a:
    if e > max2 and e < max1:
        max2 = e

if max1 == min1:
    max2 = max1

for k in a:
    if max1 == k:
        print(max2)
    else:
        print(max1)
