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 javafx.scene.layout.BorderImage;
  
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.util.*;
  import java.util.concurrent.ThreadLocalRandom;
  
  public class C {
      private static void sport(long[] a) {
          int n = a.length;
          long s=0;
          for (long i : a) {
              s+=i;
          }
          long val = 2*s;
          if (val%n!=0){
              System.out.println(0);
              return;
          }
          long target = (long) (val/n);
          long pairsCount = getPairsCount(n,target,a);
          System.out.println(pairsCount);
      }
  
      public static long countKDifference(long[] nums, long k) {
          long count = 0;
          Map<Long, Long> map = new HashMap<>();
          for (long i: nums){
              map.put(i, map.getOrDefault(i, 0L)+1);
              count += (long) map.getOrDefault(k-i, 0L);
          }
          return count;
      }
  
      public static boolean isInteger(double number){
          return Math.ceil(number) == Math.floor(number);
      }
  
      static long getPairsCount(long n, long sum,long[] arr)
      {
          HashMap<Long, Long> hm = new HashMap<>();
  
          // Store counts of all elements in map hm
          for (int i = 0; i < n; i++) {
  
              // initializing value to 0, if key not found
              if (!hm.containsKey(arr[i]))
                  hm.put(arr[i], 0L);
  
              hm.put(arr[i], hm.get(arr[i]) + 1);
          }
          long twice_count = 0;
  
          // iterate through each element and increment the
          // count (Notice that every pair is counted twice)
          for (int i = 0; i < n; i++) {
              if (hm.get((long)(sum - arr[i])) != null)
                  twice_count += (long)hm.get((long)sum - arr[i]);
  
              // if (arr[i], arr[i]) pair satisfies the
              // condition, then we need to ensure that the
              // count is decreased by one such that the
              // (arr[i], arr[i]) pair is not considered
              if (sum - arr[i] == arr[i])
                  twice_count--;
          }
  
          // return the half of twice_count
          return twice_count / 2;
      }
  
      public static void main(String[] args) throws IOException {
          FastScanner sc = new FastScanner();
          int t = sc.nextInt();
          for (int i = 0; i < t; i++) {
              int n = sc.nextInt();
              long[] a=  sc.readArrayLong(n);
              sport(a);
          }
  
      }
  
      static void shuffleArray(int[] ar) {
          // If running on Java 6 or older, use `new Random()` on RHS here
          Random rnd = ThreadLocalRandom.current();
          for (int i = ar.length - 1; i > 0; i--) {
              int index = rnd.nextInt(i + 1);
              // Simple swap
              int a = ar[index];
              ar[index] = ar[i];
              ar[i] = a;
          }
      }
  
      static class FastScanner {
          BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
          StringTokenizer st = new StringTokenizer("");
  
          String next() {
              while (!st.hasMoreTokens()) {
                  try {
                      st = new StringTokenizer(br.readLine());
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
              }
              return st.nextToken();
          }
  
          int nextInt() {
              return Integer.parseInt(next());
          }
  
          void nextLine() throws IOException {
              br.readLine();
          }
  
          long[] readArrayLong(int n) {
              long[] a = new long[n];
              for (int i = 0; i < n; i++) {
                  a[i] = nextLong();
              }
              return a;
          }
  
          int[] readArrayInt(int n) {
              int[] a = new int[n];
              for (int i = 0; i < n; i++) {
                  a[i] = nextInt();
              }
              return a;
          }
  
          long nextLong() {
              return Long.parseLong(next());
          }
  
          double nextDouble() {
              return Double.parseDouble(next());
          }
      }
  }