using System; class Program { static void Main() { int N = int.Parse(Console.ReadLine()); string[] parts = Console.ReadLine().Split(); int[] A = new int[N]; for (int i = 0; i < N; i++) A[i] = int.Parse(parts[i]); long ans = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { ans += Math.Abs(i - j) * Math.Abs(A[i] - A[j]); } } Console.WriteLine(ans); } }