import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner scn = new Scanner(System.in); int N = scn.nextInt(); int A[] = new int[N]; int sum = 0; for(int i = 0; i < N; i++){ A[i] = scn.nextInt(); } for(int i = 0; i < N; i++){ for(int j = 0; j < N; j++){ sum += Math.abs(i - j) * Math.abs(A[i] - A[j]); } } System.out.println(sum); } }