a= int(input()) *b, =map(int, input().split()) ans = 0 for i in range(a): for j in range(b): ans += abs((i-j)*(a[i]-a[j])) print(ans)