#P8196. [传智杯 #4 决赛] 三元组

[传智杯 #4 决赛] 三元组

Background

Problem Description

Given a sequence aa of length nn, for an ordered integer triple (i,j,k)(i, j, k), if it satisfies 1ijkn1 \leq i \leq j \leq k \leq n and ai+aj=aka_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 TT, indicating the number of test cases.

For each test case:

The first line is an integer, representing the length of the sequence nn.
The second line contains nn integers, where the ii-th integer represents aia_i.

Output Format

For each test case, output one line with one integer representing the answer.

2
3
1 2 3
5
1 2 3 4 5

2
6

Hint

Explanation for Sample 1

For the first test case, since a1+a1=a2a_1 + a_1 = a_2 and a1+a2=a3a_1 + a_2 = a_3, there are 22 triples in total: (1,1,2)(1, 1, 2) and (1,2,3)(1, 2, 3).
For the second test case, the six triples are:

  • (1,1,2)(1, 1, 2)
  • (1,2,3)(1, 2, 3)
  • (1,3,4)(1, 3, 4)
  • (1,4,5)(1, 4, 5)
  • (2,2,4)(2, 2, 4)
  • (2,3,5)(2, 3, 5)

Constraints

For all test points, it is guaranteed that 1T1001 \leq T \leq 100, 1n,ai1001 \leq n, a_i \leq 100, and the sum of nn over all test cases does not exceed 100100, i.e. n100\sum n \leq 100.

Translated by ChatGPT 5