#K33927. Counting Valid Triangles from Sticks
Counting Valid Triangles from Sticks
Counting Valid Triangles from Sticks
You are given a collection of sticks. Your task is to determine the number of ways to choose three distinct sticks to form a non-degenerate triangle. A triangle is non-degenerate if it satisfies the triangle inequality conditions:
\(a+b>c, \quad a+c>b, \quad b+c>a\),
where \(a\), \(b\), and \(c\) are the lengths of the chosen sticks. For each test case, compute the total number of valid triangles that can be formed.
inputFormat
The first line contains an integer \(T\) representing the number of test cases.
Each test case is described in the following format:
- A line with an integer \(n\) denoting the number of sticks.
- A line with \(n\) space-separated integers representing the lengths of the sticks.
outputFormat
For each test case, output a single line containing the number of valid triangles that can be formed.
## sample3
3
3 4 5
4
6 8 10 12
5
1 1 1 1 1
1
4
10
</p>