Evenly Spaced Triples
InterviewTime limit1sMemory limit256 MB
Given N distinct positions on a line, count how many triples of points have the middle point exactly halfway between the other two.
Problem
There are distinct points marked on a line. Point sits at position .
Pick three of the points and call the leftmost one , the middle one , and the rightmost one , at positions , , and . The three points are evenly spaced when the distance between and equals the distance between and , that is, when .
Here is an example with .

The points sit at -4, -1, 0, 2, and 4. Taking -4, -1, 0 as , , gives and , so the spacing is not equal. Taking -4, -1, 2 gives and , so those three points are evenly spaced. In this example the evenly spaced triples are (-4, -1, 2), (-4, 0, 4), and (0, 2, 4), so there are 3 of them.
Given the positions of the points, write a program that counts how many evenly spaced triples there are.
Input
The first line contains , the number of test cases. The test cases follow.
The first line of each test case contains the number of points (). The second line contains the positions separated by spaces. Every position is an integer between -100,000,000 and 100,000,000, and all positions are distinct.
Output
For each test case, print the number of evenly spaced triples , , on its own line, in the order the test cases are given.