Loading...
Beautiful Triangle
Time: 1 s
Memory: 500 MB
Shafi wanted to eat with his special friend in a fancy restaurant on the 14th of February. As he was broke, he needed some money . He asked his father to give him some . After hearing the request, his father, who was a genius mathematician, gave him a task to solve. He told him that if he could solve the task, he would give him twice the money he requested. Being the topper of his class, he solved the problem easily. Now, can you solve the problem?

Initially, you are given n sticks, numbered from 1 to n. You have to form a beautiful triangle with the n sticks. It takes three sticks of equal length to form a beautiful triangle. You have to calculate the number of ways to choose exactly 3 sticks so that a beautiful triangle can be formed out of them.
Input
The first line contains one integer t(1<=t<=100) — the number of test cases.
Each test case consists of two lines:
First line contains one integer n(1<=n<=\(10^4\)).
The next line contains n integers a1,a2,a3….,an(1<=ai<=n).
 
Output
For each test case, print one integer — the number of ways to choose exactly 3 sticks so that a beautiful triangle can be formed out of them.
Examples
Input
Output
3
4
1 2 3 1
6
1 2 1 1 3 1
20
1 6 2 3 1 6 6 1 2 3 6 5 4 7 10 6 9 8 6 1
0
4
24
Notes
In testcase 1, we can see that there is no way we can form a triangle since there are only two sticks of equal length.

In testcase 2, the total number of ways is 4.
  • First way: 1st stick, 3rd stick, 4th stick
  • Second way: 1st stick, 3rd stick, 6th stick
  • Third way: 1st stick, 4th stick, 6th stick
  • Fourth way: 3rd stick, 4th stick, 6th stick
Problem Info
Problem ID 223
Time Limit 1000 ms
Memory Limit 512000 KB
Moderators DilligentArchon , Alom_Shanto
Statistics
Submit
You need to Login or Registration for submit your solution