#P7556. [USACO21OPEN] Do You Know Your ABCs? S

[USACO21OPEN] Do You Know Your ABCs? S

Description

Farmer John’s cows are holding their daily meeting on the mooZ video conferencing platform. They have invented a simple number game to make the meeting more fun.

Elsie has three positive integers AA, BB, and CC (1ABC1\le A\le B\le C). These numbers are secret, and she will not tell them directly to her sister Bessie. She tells Bessie NN (4N74\le N\le 7) distinct integers x1,x2,,xNx_1,x_2,\ldots,x_N (1xi1091\le x_i\le 10^9), and claims that each xix_i is one of AA, BB, CC, A+BA+B, B+CB+C, C+AC+A, or A+B+CA+B+C. However, Elsie may be lying; these integers xix_i might not correspond to any valid (A,B,C)(A,B,C).

Bessie cannot figure it out, so you need to compute the number of triples (A,B,C)(A,B,C) that are consistent with the numbers Elsie provided.

Each input contains TT (1T1001\le T\le 100) test cases that must be solved independently.

Input Format

The first line of input contains TT.

For each test case, the first line contains NN, the number of integers Elsie gave to Bessie.

The second line of each test case contains NN distinct integers x1,x2,,xNx_1,x_2,\ldots,x_N.

Output Format

For each test case, output the number of triples (A,B,C)(A,B,C) that are consistent with the numbers Elsie provided.

10
7
1 2 3 4 5 6 7
4
4 5 7 8
4
4 5 7 9
4
4 5 7 10
4
4 5 7 11
4
4 5 7 12
4
4 5 7 13
4
4 5 7 14
4
4 5 7 15
4
4 5 7 16
1
3
5
1
4
3
0
0
0
1

Hint

Sample Explanation

For x={4,5,7,9}x=\{4,5,7,9\}, the five possible triples are:

$$(2, 2, 5), (2, 3, 4), (2, 4, 5), (3, 4, 5), (4, 5, 7).$$

Test Point Properties

  • In test points 141 \sim 4, all xix_i are at most 5050.
  • Test points 555 \sim 5 satisfy N=7N=7.
  • Test points 7157 \sim 15 have no additional constraints.

Notes

Problem author: Benjamin Qi.

Translated by ChatGPT 5