Koothrappali and Stars

0

0 votes
Hard
Problem

Rajesh is observing the night sky through his telescope and has calculated the distance of N stars from Earth and arranged the distances in a sequence D. Now, he wants to generate some stats.

He wants to count the number of triplets of stars such that if their indices are x, y and z, following conditions must be satisfied--

  • 1x<y<zN

  • DyDx=DzDy

Since, the data set is too big and Rajesh wo't be able to finish it in time, he requires your help.

Input Format:

First line contains T, number of test cases.

First line of each test case contains N, number of stars.

Second line of each test case contains N integers denoting the distance sequence D.

Output Format:

For each test case, output the required answer in separate lines.

Constraints:

1T10

3N105

1Di105

Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

For first case, only triplet which satisfies the above conditions is (1, 2, 3).

For second case, triplets satisfying the conditions are (3, ,4, 5) and (3, 5, 7).

Editor Image

?