parseInt(x)=parse(Int, x)
parseMap(x::Array{SubString{String},1})=map(parseInt, x)

function main()
	n = readline() |> parseInt
	a = readline() |> split |> parseMap
	b = Tuple{Int,Int,Int}[]
	for i in 1:n
		for j in 1:n
			push!(b,(i,j,a[i]*abs(i-j)))
		end
	end
	b = sort(b,by=x->x[3],rev=true)
	ans = -ones(Int,n)
	used = zeros(Int,n)
	for i in 1:n*n
		(p,q,r) = b[i]
		if ans[q]==-1&&used[p]==0
			used[p]=1
			ans[q]=r
		end
	end
	println(sum(ans))
end

main()