N = int(input())
L = []
for l in range(N):
	L.append(int(input()))

maxL = max(L)
num = ["n"] * N

if L.count(maxL) >= 2:
	for i in range(N):
		print(maxL)
		
else:
	L = L.remove(maxL)
	secL = max(L)
	
	for i in range(N):
		if i in num:
			print(secL)
		else:
			print(maxL)
