n = io.read("*n") a = {} for i = 1, n do a[i] = io.read("*n") end ans = 0 for i = 1, n do for j = 1, n do ans = ans + math.abs(i - j) * math.abs(a[i] - a[j]) end end print(ans)