Hard Sums

0

0 votes
Math
Problem

Given a list of N numbers a1,a2,...,aN, your task is to count the following sum.

Ni=1Nj=1Nk=1ai.aj.ak

You need to do this for T test cases.

Constraints

1T10

1N105

0ai9

Input Format

The first line contains a single integer T denoting the number of test cases.

For each test case, the first line contains a single integer N.

The second line of each test case contains N integers a1,a2,...,aN.

Output Format

For each test case, print one integer, i.e., the answer in a single line.

Subtasks

  • 10 points: 1N100
  • 90 points: original constraints

Note: The final answer may not fit into a 32-bit integer.

Sample Input
1
4
1 2 4 8
Sample Output
3375
Time Limit: 1.5
Memory Limit: 256
Source Limit:
Editor Image

?