import sys

input = sys.stdin.readline



n = int(eval(input()))

numbers = [int(eval(input())) for i in range(n)]





m1,m2 = sorted(numbers, reverse=1)[:2]



b = [m2 if x==m1 else m1 for x in numbers]

for s in b:

    print(s)
import sys

input = sys.stdin.readline



n = int(eval(input()))

numbers = [int(eval(input())) for i in range(n)]



a1,a2 = sorted(numbers, reverse=1)[:2]

b = [a2 if x==a1 else a1 for x in numbers]

print(('\n'.join(map(str,b))))
import sys

input = sys.stdin.readline
n = int(eval(input()))
numbers = [int(eval(input())) for i in range(n)]
m1, m2 = sorted(numbers, reverse=1)[:2]
b = [m2 if x == m1 else m1 for x in numbers]
for s in b:
    print(s)

import sys

input = sys.stdin.readline
n = int(eval(input()))
numbers = [int(eval(input())) for i in range(n)]
a1, a2 = sorted(numbers, reverse=1)[:2]
b = [a2 if x == a1 else a1 for x in numbers]
print(("\n".join(map(str, b))))

-m1, m2 = sorted(numbers, reverse=1)[:2] -b = [m2 if x == m1 else m1 for x in numbers] -for s in b: -    print(s) +a1, a2 = sorted(numbers, reverse=1)[:2] +b = [a2 if x == a1 else a1 for x in numbers] +print(("\n".join(map(str, b))))