n,*a=map(int,open(0).read().split())
b=list(range(n))
def f():
	for i, x in enumerate(a):
		for j in range(n):
			if abs(b[i]-i)*a[i]+abs(b[j]-j)*a[j]<abs(b[j]-i)*a[i]+abs(b[i]-j)*a[j]:
				b[i],b[j]=b[j],b[i]
exec("f();"*15)
print(sum(x*abs(i-b[i]) for i,x in enumerate(a)))