N = int(input()) A = list(map(int, input().split())) if N > 100: print(0) exit() ans = 0 for i in range(N): for j in range(N): ans += abs(A[i] - A[j]) * abs(i - j) print(ans)