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