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

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

if L.count(maxL) >= 2:
	for i in range(N):
		print(maxL)
		
else:
	for i in range(N):
		if L[i] == maxL:
			num[i] = i
			L[i] = 0
	
	if max(L) != 0:
		secL = max(L)
	else:
		secL = max(subL)
	
	for i in range(N):
		if i in num:
			print(secL)
		else:
			print(maxL)

