Question: 
Write a python function to find the sum of absolute differences in all pairs of the given array.


Model's Code:
def sum_Pairs(arr, n):
    arr.sort()
    total_sum = 0
    for i in range(n):
        total_sum += (2 * i - n + 1) * arr[i]
    return total_sum



Sample Correct Code:
def sum_Pairs(arr,n): 
    sum = 0
    for i in range(n - 1,-1,-1): 
        sum += i*arr[i] - (n-1-i) * arr[i] 
    return sum


Asserts:
assert sum_Pairs([1,8,9,15,16],5) == 74
assert sum_Pairs([1,2,3,4],4) == 10
assert sum_Pairs([1,2,3,4,5,7,9,11,14],9) == 188


Tests:
Test 1 of 3: PASS
Test 2 of 3: PASS
Test 3 of 3: PASS

Test 144 of 974: 104/144 (72.22222222222221%): success