n = int(input())
a = [int(input()) for i in range(n)]
m1 = max(a)
if len(set(a)) == 1:
	for i in range(n):
		print(m1)
else:
	m2 = sorted(set(a))[-2]
	for i in range(n):
		if a[i] < m1:
			print(m1)
		elif a[i] == m1:
			if a.count(m1) > 1:
				print(m1)
			else:
				print(m2)
		else:
			print(m2)