## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

## Akash and Equal Mean Solution | CodeChef Problem Solution 2022

Akash goes to class everyday. His classes are held on the ${9}^{th}$ floor so he uses a lift. One day $N$ people get on the lift. However, since the lift can carry at most $N-2$ people, $2$ of them need to get off.

Given an array $A$ of the weights of the $N$ people, Akash wonders how many ways of removing $2$ people exist such that the mean of weights of the people in the lift remains constant. In other words, the mean of weights of the $N-2$ people remaining in the lift must be the same as the mean of weights of all the $N$ people who were initially on the lift. Help Akash find how many such ways exist.

### Input Format

• The first line contains a single integer $T$ - the number of test cases. Then the test cases follow.
• The first line of each test case contains an integer $N$ - the number of people who get on the lift initially.
• The second line of each test case contains $N$ space-separated integers ${A}_{1},{A}_{2},\dots ,{A}_{N}$ denoting the weights of the $N$ people on the lift.

### Output Format

For each test case, print a single integer denoting the number of ways of removing $2$ people such that the mean reamins the same.

### Constraints

• $1\le T\le 1000$
• $3\le N\le {10}^{5}$
• $1\le {A}_{i}\le {10}^{9}$
• Sum of $N$ over all test cases does not exceed $2\cdot {10}^{5}$

### Sample Input 1

3
4
1 3 5 7
4
1 7 7 7
6
1 1 1 1 1 1


### Sample Output 1

2
0
15


### Explanation

Test case $1$: The mean of weights of all $N$ students is $\frac{1+3+5+7}{4}=\frac{16}{4}=4$.

• Consider removing the people with weights $\left(1,7\right)$. The mean of weights of the $N-2$ people remaining in the lift is $\frac{3+5}{2}=\frac{8}{2}=4$, which is same as the mean of all $N$ people.
• Consider removing the people with weights $\left(3,5\right)$. The mean of weights of the $N-2$ people remaining in the lift is $\frac{1+7}{2}=\frac{8}{2}=4$, which is same as the mean of all $N$ people.

There is no other way to remove $2$ people such that the mean reamins the same. Hence the answer is $2$.

Test case $2$: The mean of weights of all $N$ students is $\frac{1+7+7+7}{4}=5.5$. It can be seen that there is no way to remove $2$ people such that the mean reamins the same. Hence the answer is $0.$