N=int(input())
A=list(map(int, input().split()))

B = list(zip(A, list(range(N))))

if N%2==0:left, right = N//2, N//2
else:left, right = N//2+1, N//2
  

B_l = B[:left]
B_r = B[right:]

C = sorted(B_r, key=lambda x: x[0], reverse=True) + sorted(B_l,key=lambda x: x[0], )

sum_ = 0
for i in range(N):
  sum_ += abs(C[i][1] - i)*C[i][0]
print(sum_)