SP18155 ABSP1 - abs(a-b) I

Description

Recently Mr. Kopa Samsu is learning programming. On a very renowned online judge, he found a problem: You are given an array of N numbers in non-decreasing order. You have to answer the summation of the absolute difference of all distinct pairs in the given array. Do you know what distinct pair means? Suppose you have an array of 3 elements: 3 5 6 Then all the distinct pairs are: 3 5 3 6 5 6 For this problem, Mr. Kopa Samsu implemented an algorithm to find the summation of the absolute difference of all distinct pairs. His algorithm was: ``` int ABS(int a[], int n) {     int sum = 0;     for (int i = 1; i

Input Format

The input data set starts with an integer T (T

Output Format

Every test case should output an integer “X”, where X is the summation of the absolute difference of all the distinct pair.