n = int(input())
a = [int(input()) for i in range(n)]
m = max(a)

k = [i for i, x in enumerate(a) if x == m]

if len(k)>=2:
	for i in range(n):
		print(m)
else:
	b = a
	b.pop(m)
	m2 = max(b)
	for i in range(n):
		if i != m:
			print(m)
		else:
			print(m2)