P8196 [ChuanZhi Cup #4 Finals] Triples
Background
Description
Given a sequence $a$ of length $n$, for an ordered integer triple $(i, j, k)$, if it satisfies $1 \leq i \leq j \leq k \leq n$ and $a_i + a_j = a_k$, then we call this triple “ChuanZhi’s”.
Now please compute how many ordered integer triples are “ChuanZhi’s”.
Input Format
**This problem contains multiple groups of testdata in a single test case**.
The first line of input is an integer $T$, indicating the number of test cases.
For each test case:
The first line is an integer, representing the length of the sequence $n$.
The second line contains $n$ integers, where the $i$-th integer represents $a_i$.
Output Format
For each test case, output one line with one integer representing the answer.
Explanation/Hint
### Explanation for Sample 1
For the first test case, since $a_1 + a_1 = a_2$ and $a_1 + a_2 = a_3$, there are $2$ triples in total: $(1, 1, 2)$ and $(1, 2, 3)$.
For the second test case, the six triples are:
- $(1, 1, 2)$
- $(1, 2, 3)$
- $(1, 3, 4)$
- $(1, 4, 5)$
- $(2, 2, 4)$
- $(2, 3, 5)$
### Constraints
For all test points, it is guaranteed that $1 \leq T \leq 100$, $1 \leq n, a_i \leq 100$, and the sum of $n$ over all test cases does not exceed $100$, i.e. $\sum n \leq 100$.
Translated by ChatGPT 5