using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); public static void Main() { Solve(); } static void Solve() { var n = NN; var a = NList; if (n > 100) return; var ans = 0; for (var i = 0; i < n; ++i) for (var j = 0; j < n; ++j) ans += Math.Abs(i - j) * Math.Abs(a[i] - a[j]); WriteLine(ans); } }