Delete Two Elements solution Codeforces

Delete Two Elements solution Codeforces

Monocarp has got an array 𝑎a consisting of 𝑛n integers. Let’s denote 𝑘k as the mathematic mean of these elements (note that it’s possible that 𝑘k is not an integer).

The mathematic mean of an array of 𝑛n elements is the sum of elements divided by the number of these elements (i. e. sum divided by 𝑛n).

Monocarp wants to delete exactly two elements from 𝑎a so that the mathematic mean of the remaining (𝑛−2)(n−2) elements is still equal to 𝑘k.

Your task is to calculate the number of pairs of positions [𝑖,𝑗][i,j] (𝑖<𝑗i<j) such that if the elements on these positions are deleted, the mathematic mean of (𝑛−2)(n−2) remaining elements is equal to 𝑘k (that is, it is equal to the mathematic mean of 𝑛n elements of the original array 𝑎a).

Input

The first line contains a single integer 𝑡t (1≤𝑡≤1041≤t≤104) — the number of testcases.

The first line of each testcase contains one integer 𝑛n (3≤𝑛≤2⋅1053≤n≤2⋅105) — the number of elements in the array.

The second line contains a sequence of integers 𝑎1,𝑎2,…,𝑎𝑛a1,a2,…,an (0≤𝑎𝑖≤1090≤ai≤109), where 𝑎𝑖ai is the 𝑖i-th element of the array.

The sum of 𝑛n over all testcases doesn’t exceed 2⋅1052⋅105.

Output

Print one integer — the number of pairs of positions [𝑖,𝑗][i,j] (𝑖<𝑗i<j) such that if the elements on these positions are deleted, the mathematic mean of (𝑛−2)(n−2) remaining elements is equal to 𝑘k (that is, it is equal to the mathematic mean of 𝑛n elements of the original array 𝑎a).

Example
input

Copy
4
4
8 8 8 8
3
50 20 10
5
1 4 7 3 5
7
1 2 3 4 5 6 7
output

Copy
6
0
2
3
Note

In the first example, any pair of elements can be removed since all of them are equal.

In the second example, there is no way to delete two elements so the mathematic mean doesn’t change.

In the third example, it is possible to delete the elements on positions 11 and 33, or the elements on positions 44 and 55.

Leave a Comment