n=int(input())
alis=[int(input()) for i in range(n)]
anslis=[0]*n
if alis.count(max(alis))>=2:
	for i in range(n):
		print(max(alis))
else:
	for i in range(n):
		if i!=alis.index(max(alis)):
			print(max(alis))
		else:
			print(sorted(alis)[-2])