n,*a=map(int,open(0).read().split())
b=list(range(n))
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]
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]
print(sum(x*abs(i-b[i]) for i,x in enumerate(a)))