Adding Special Sum

All submissions for this problem are available.
Read problems statements in Mandarin Chinese and Russian as well.
Special Sum of 4 numbers (a, b, c, d) is defined as:
a+bcd + a+cbd + a+dbc + c+dab + b+dac + b+cad
where x denotes absolute value of x.
Read problems statements in Mandarin Chinese and Russian as well.
Special Sum of 4 numbers (a, b, c, d) is defined as:
a+bcd + a+cbd + a+dbc + c+dab + b+dac + b+cad
where x denotes absolute value of x.
Given an array A of size N, you need to find the sum of Special Sum of numbers taken over all quadruples of different indices of the array.
Input
First line contains T, the number of test cases to follow.
First line of each test case contains the only integer N.
Second line of each test case contains the array as N space separated integers.
Output
For each test case output the sum as explained above.
Constraints
 1 ≤ T ≤ 100
 4 ≤ N ≤ 1000
 1 ≤ Elements of the array ≤ 10^{5}
 1 ≤ Sum of N over all test case ≤ 2000
Example
Input: 3 4 1 2 3 3 5 1 2 3 4 5 6 9 18 28 23 12 9 Output: 10 76 1176
Explanation:
Test Case 1: SpecialSum(1,2,3,3) = 10 .
Test Case 2: SpecialSum(1,2,3,4) + SpecialSum(1,2,3,5) + SpecialSum(1,2,4,5)+ SpecialSum(1,3,4,5) + SpecialSum(2,3,4,5) are called.
Author:  devuy11 
Tester:  adurysk 
Editorial  http://discuss.codechef.com/problems/COMB4SUM 
Tags  cook60, devuy11, easymedium 
Date Added:  9062015 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions