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