description: 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 (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 (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 ≤ t ≤ 10^4) — the number of testcases.
  
  The first line of each testcase contains one integer n (3 ≤ n ≤ 2 ⋅ 10^5) — the number of elements in the array.
  
  The second line contains a sequence of integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^{9}), where a_i is the i-th element of the array.
  
  The sum of n over all testcases doesn't exceed 2 ⋅ 10^5.
  
  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 (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
  
  
  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
  
  
  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 1 and 3, or the elements on positions 4 and 5.
solution: import java.io.*;
  import java.util.*;
  
  public class CodeForces{
      /*****************************************WRITING CODE STARTS HERE******************************************/
      public static void main(String[] args) throws IOException{
          openIO();
          int testCase = 1;
          testCase = sc.nextInt();
          preCompute();
          for (int i = 1; i <= testCase; i++) solve(i);
          closeIO();
      }
  
      public static void solve(int tCase)throws IOException {
          int n = sc.nextInt();
          int[] arr = new int[n];
          for(int i=0;i<n;i++)arr[i] = sc.nextInt();
          Map<Long,Integer> map = new HashMap<>();
          long sum = 0;
          for(int ele : arr)sum+=ele;
          long count = 0;
          for(int i=0;i<n;i++){
  
              long x = 2*sum / n - arr[i];
              if((2*sum) % n ==0)count += map.getOrDefault(x,0);
              map.put((long) arr[i], 1 + map.getOrDefault((long) arr[i],0));
          }
          out.println(count);
  
      }
  
  
  
      private static void  preCompute(){
  
      }
      /*****************************************WRITING CODE ENDS HERE******************************************/
      static FastestReader sc;
      static PrintWriter out;
      private static void openIO() throws IOException{
          sc = new FastestReader();
          out = new PrintWriter(System.out);
      }
  
      /**************************************HELPER FUNCTION STARTS HERE ************************************/
  
      public static final int mod = (int) 1e9 +7;
      private static final int mod2 =  998244353;
      public static final int inf_int = (int) 2e9;
      public static  final long inf_long = (long) 1e15;
  
      // euclidean algorithm time O(max (loga ,logb))
      public static long _gcd(long a, long b) {
          long x = Math.min(a, b);
          long y = Math.max(a, b);
          if (y % x == 0) return x;
          return _gcd(y % x, x);
      }
  
      public static long _lcm(long a, long b) {
          // lcm(a,b) * gcd(a,b) = a * b
          return (a / _gcd(a, b)) * b;
      }
      // binary exponentiation time O(logn)
      public static long _power(long x, long n) {
          long ans = 1;
          while (n > 0) {
              if ((n & 1) == 1) {
                  ans *= x;
                  ans %= mod;
                  n--;
              } else {
                  x *= x;
                  x %= mod;
                  n >>= 1;
              }
          }
          return ans;
      }
      //sieve/first divisor time : O(mx * log ( log (mx) ) )
      public static int[]  _seive(int mx){
          int[] firstDivisor = new int[mx+1];
          for(int i=0;i<=mx;i++)firstDivisor[i] = i;
          for(int i=2;i*i<=mx;i++)
              if(firstDivisor[i] == i)
                  for(int j = i*i;j<=mx;j+=i)
                      firstDivisor[j] = i;
          return firstDivisor;
      }
  
  
      /**************************************HELPER FUNCTION ENDS HERE ************************************/
  
      /*****************************************FAST INPUT STARTS HERE *************************************/
  
      public static void closeIO() throws IOException{
          out.flush();
          out.close();
          sc.close();
      }
      private static final class FastestReader {
          private static final int BUFFER_SIZE = 1 << 16;
          private final DataInputStream din;
          private final byte[] buffer;
          private int bufferPointer, bytesRead;
  
          public FastestReader() {
              din = new DataInputStream(System.in);
              buffer = new byte[BUFFER_SIZE];
              bufferPointer = bytesRead = 0;
          }
  
          public FastestReader(String file_name) throws IOException {
              din = new DataInputStream(new FileInputStream(file_name));
              buffer = new byte[BUFFER_SIZE];
              bufferPointer = bytesRead = 0;
          }
  
          private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
  
          private int skip() throws IOException {
              int b;
              //noinspection StatementWithEmptyBody
              while ((b = read()) != -1 && isSpaceChar(b)) {}
              return b;
          }
  
          public String next() throws IOException {
              int b = skip();
              final StringBuilder sb = new StringBuilder();
              while (!isSpaceChar(b)) { // when nextLine, (isSpaceChar(b) && b != ' ')
                  sb.appendCodePoint(b);
                  b = read();
              }
              return sb.toString();
          }
  
          public int nextInt() throws IOException {
              int ret = 0;
              byte c = read();
              while (c <= ' ') {
                  c = read();
              }
              final boolean neg = c == '-';
              if (neg) { c = read(); }
              do {
                  ret = ret * 10 + c - '0';
              } while ((c = read()) >= '0' && c <= '9');
  
              if (neg) { return -ret; }
              return ret;
          }
  
          public long nextLong() throws IOException {
              long ret = 0;
              byte c = read();
              while (c <= ' ') { c = read(); }
              final boolean neg = c == '-';
              if (neg) { c = read(); }
              do {
                  ret = ret * 10 + c - '0';
              } while ((c = read()) >= '0' && c <= '9');
              if (neg) { return -ret; }
              return ret;
          }
  
          public double nextDouble() throws IOException {
              double ret = 0, div = 1;
              byte c = read();
              while (c <= ' ') { c = read(); }
              final boolean neg = c == '-';
              if (neg) { c = read(); }
  
              do {
                  ret = ret * 10 + c - '0';
              } while ((c = read()) >= '0' && c <= '9');
  
              if (c == '.') {
                  while ((c = read()) >= '0' && c <= '9') {
                      ret += (c - '0') / (div *= 10);
                  }
              }
  
              if (neg) { return -ret; }
              return ret;
          }
  
          private void fillBuffer() throws IOException {
              bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
              if (bytesRead == -1) { buffer[0] = -1; }
          }
  
          private byte read() throws IOException {
              if (bufferPointer == bytesRead) { fillBuffer(); }
              return buffer[bufferPointer++];
          }
  
          public void close() throws IOException {
              din.close();
          }
  
      }
      /*****************************************FAST INPUT ENDS HERE *************************************/
  }