n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
max1 = 0
for j in a:
    if j > max1:
        max1 = j
max2 = 0
for t in a:
    if t > max2 and t < max1:
        max2 = t
check = 0
for q in range(n-1):
    if a[q] != a[q+1]:
        check = 1

if check == 0:
    max2 = max1

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