n = int(eval(input()))

data = [int(eval(input())) for k in range(n)]

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

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

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

input = sys.stdin.readline



n = int(eval(input()))

data = [int(eval(input())) for k in range(n)]

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

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

print(('\n'.join(map(str,b))))
n = int(eval(input()))
data = [int(eval(input())) for k in range(n)]
m1, m2 = sorted(data, reverse=1)[:2]
b = [m2 if x == m1 else m1 for x in data]
print(("\n".join(map(str, b))))

import sys

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

+import sys + +input = sys.stdin.readline