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.DataInputStream;
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.IOException;
  import java.io.PrintStream;
  import java.io.PrintWriter;
  import java.util.ArrayList;
  import java.util.Collections;
  import java.util.Comparator;
  import java.util.HashMap;
  import java.util.HashSet;
  import static java.lang.Math.min;
  import static java.lang.Math.max;
  import static java.lang.Math.abs;
  
  public class Main {
  	static boolean DEBUG = false;
  
  	public static void main(String[] args) throws IOException {
  		Comparator<pair> com = (p1,
  				p2) -> ((p1.first > p2.first || (p1.first == p2.first && p1.second > p2.second)) ? 1 : -1);
  		if (System.getProperty("ONLINE_JUDGE") == null) {
  			System.setIn(new FileInputStream(new File("D://program//javaCPEclipse//MyJava//src//MyJava//input.txt")));
  			// System.setOut(new PrintStream(new File("output.txt")));
  			System.setErr(new PrintStream(new File("D://program//javaCPEclipse//MyJava//src//MyJava//error.txt")));
  			DEBUG = true;
  		}
  		Reader fs = new Reader();
  		PrintWriter pw = new PrintWriter(System.out);
  		int t = fs.nextInt();
  		while (t-- > 0) {
  			int n = fs.nextInt();
  			Long sum = 0l;
  			ArrayList<Long> temp = new ArrayList<Long>();
  			for (int i = 0; i < n; i++) {
  				temp.add(fs.nextLong());
  				sum += temp.get(i);
  			}
  			HashMap<Long, Long> a = new HashMap<Long, Long>();
  			for (int i = 0; i < n; i++) {
  				Long value = a.get(temp.get(i));
  				a.put(temp.get(i), value == null ? 1 : value + 1);
  			}
  			long x = 2 * sum;
  			if (x % n != 0) {
  				pw.println(0);
  				continue;
  			}
  			HashMap<Long, Boolean> mp = new HashMap<Long, Boolean>();
  			for (int i = 0; i < n; i++) {
  				mp.put(temp.get(i), false);
  			}
  			long mus = x / n;
  			long ans = 0;
  			for (int i = 0; i < n; i++) {
  				long cur = temp.get(i);
  				long req = mus - cur;
  				if (a.get(req) == null)
  					continue;
  				if (mp.get(req) && mp.get(cur))
  					continue;
  				if (cur == req) {
  					long pp = a.get(req);
  					ans += (pp * pp - pp) / 2;
  					mp.put(req, true);
  				} else {
  					ans += a.get(req) * a.get(cur);
  					mp.put(cur, true);
  					mp.put(req, true);
  				}
  			}
  			pw.println(ans);
  		}
  		fs.close();
  		pw.close();
  	}
  
  	static void debug(int a[], String l) {
  		if (DEBUG) {
  			System.err.print("l-> [");
  			for (int x : a)
  				System.err.print(x + " ");
  			System.err.println("]");
  		}
  	}
  
  	static void debug(long a[], String l) {
  		if (DEBUG) {
  			System.err.print("l-> [");
  			for (long x : a)
  				System.err.print(x + " ");
  			System.err.println("]");
  		}
  	}
  
  	static <T> void debug(HashSet<Integer> a, String l) {
  		if (DEBUG) {
  			System.err.println(l + " -> ");
  			System.err.println(a);
  		}
  	}
  
  	static void debug(String a, String l) {
  		if (DEBUG) {
  			System.err.println(l + " -> " + a);
  		}
  	}
  
  	static void debug(StringBuilder a, String l) {
  		if (DEBUG) {
  			System.err.println(l + " -> " + a);
  		}
  	}
  
  	static <T extends Number, V extends T> void debug(HashMap<T, V> a, String l) {
  		if (DEBUG) {
  			System.err.println(l + " -> ");
  			System.err.println(a);
  		}
  	}
  
  	static <T extends Number> void debug(T a, String l) {
  		if (DEBUG) {
  			System.err.println(l + " -> " + a);
  		}
  	}
  
  	static <T extends Number> void debug(T[] a, String l) {
  		if (DEBUG) {
  			System.err.print(l + " -> \n" + "[ ");
  			for (int i = 0; i < a.length; i++) {
  				System.err.print(a[i] + " ");
  			}
  			System.err.println("]");
  		}
  	}
  
  	static <T> void debug(ArrayList<T> a, String l) {
  		if (DEBUG) {
  			System.err.print(l + " -> ");
  			System.err.print("[ ");
  			for (T q : a) {
  				System.err.print(q + " ");
  			}
  			System.err.println("]");
  		}
  	}
  
  	static boolean primeFactors(long n, long b) {
  		while (n % 2 == 0) {
  			if (b % 2 != 0)
  				return false;
  			n = n / 2;
  		}
  		for (long i = 3; i * i <= n; i = i + 2) {
  			while (n % i == 0) {
  				if (b % i != 0)
  					return false;
  				n = n / i;
  			}
  		}
  		if (n > 2)
  			if (b % n != 0)
  				return false;
  		return true;
  	}
  
  	public static long __gcd(long a, long b) {
  		if (b != 0) {
  			return __gcd(b, a % b);
  		} else {
  			return a;
  		}
  	}
  
  	public static int lower_bound(ArrayList<Integer> ar, int k) {
  		int s = 0;
  		int e = ar.size();
  		while (s != e) {
  			int mid = s + e >> 1;
  			if (ar.get(mid) < k) {
  				s = mid + 1;
  			} else {
  				e = mid;
  			}
  		}
  		if (s == ar.size()) {
  			return -1;
  		}
  		return s;
  	}
  
  	public static int upper_bound(ArrayList<Integer> ar, int k) {
  		int s = 0;
  		int e = ar.size();
  		while (s != e) {
  			int mid = s + e >> 1;
  			if (ar.get(mid) <= k) {
  				s = mid + 1;
  			} else {
  				e = mid;
  			}
  		}
  		if (s == ar.size()) {
  			return -1;
  		}
  		return s;
  	}
  
  	static final int MAXN = (int) 1e7;
  
  	// stores smallest prime factor for every number
  	static int spf[] = new int[MAXN];
  
  	// Calculating SPF (Smallest Prime Factor) for every
  	// number till MAXN.
  	// Time Complexity : O(nloglogn)
  	static void sieve() {
  		spf[1] = 1;
  		for (int i = 2; i < MAXN; i++)
  
  			// marking smallest prime factor for every
  			// number to be itself.
  			spf[i] = i;
  
  		// separately marking spf for every even
  		// number as 2
  		for (int i = 4; i < MAXN; i += 2)
  			spf[i] = 2;
  
  		for (int i = 3; i * i < MAXN; i++) {
  			// checking if i is prime
  			if (spf[i] == i) {
  				// marking SPF for all numbers divisible by i
  				for (int j = i * i; j < MAXN; j += i)
  
  					// marking spf[j] if it is not
  					// previously marked
  					if (spf[j] == j)
  						spf[j] = i;
  			}
  		}
  	}
  
  	// A O(log n) function returning primefactorization
  	// by dividing by smallest prime factor at every step
  	static ArrayList<Integer> getFactorization(int x) {
  		ArrayList<Integer> ret = new ArrayList<>();
  		while (x != 1) {
  			ret.add(spf[x]);
  			x = x / spf[x];
  		}
  		return ret;
  	}
  
  	public static ArrayList<Integer> sieve(int n) {
  		int[] prime = new int[n + 1];
  		ArrayList<Integer> ans = new ArrayList<Integer>();
  		for (int p = 2; p <= n; p++) {
  			if (prime[p] == 0) {
  				ans.add(p);
  				for (int i = p * p; i <= n; i += p) {
  					prime[i] = 1;
  				}
  			}
  		}
  		return ans;
  	}
  
  	static class Reader {
  		final private int BUFFER_SIZE = 1 << 16;
  		private DataInputStream din;
  		private byte[] buffer;
  		private int bufferPointer, bytesRead;
  
  		public Reader() {
  			din = new DataInputStream(System.in);
  			buffer = new byte[BUFFER_SIZE];
  			bufferPointer = bytesRead = 0;
  		}
  
  		public Reader(String file_name) throws IOException {
  			din = new DataInputStream(new FileInputStream(file_name));
  			buffer = new byte[BUFFER_SIZE];
  			bufferPointer = bytesRead = 0;
  		}
  
  		public String next() throws IOException {
  			byte[] buf = new byte[100009];
  			int cnt = 0, c;
  			while ((c = read()) != -1) {
  				if (c <= ' ') {
  					if (cnt != 0) {
  						break;
  					} else {
  						continue;
  					}
  				}
  				buf[cnt++] = (byte) c;
  			}
  			return new String(buf, 0, cnt);
  		}
  
  		public int nextInt() throws IOException {
  			int ret = 0;
  			byte c = read();
  			while (c <= ' ') {
  				c = read();
  			}
  			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();
  			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();
  			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 int[] readArray(int n) throws IOException {
  			int[] arr = new int[n];
  			for (int i = 0; i < n; i++) {
  				arr[i] = nextInt();
  			}
  			return arr;
  		}
  
  		public int[] readArray(int n, int x) throws IOException {
  			int[] arr = new int[n + x];
  			for (int i = x; i < n + x; i++) {
  				arr[i] = nextInt();
  			}
  			return arr;
  		}
  
  		public ArrayList<Integer> readList(int n) throws IOException {
  			ArrayList<Integer> a = new ArrayList<Integer>();
  			for (int i = 0; i < n; i++) {
  				a.add(nextInt());
  			}
  			return a;
  		}
  
  		public int[][] read2Array(int n, int m) throws IOException {
  			int[][] a = new int[n][m];
  			for (int i = 0; i < n; i++) {
  				for (int j = 0; j < m; j++) {
  					a[i][j] = nextInt();
  				}
  			}
  
  			return a;
  		}
  
  		public void close() throws IOException {
  			if (din == null)
  				return;
  			din.close();
  		}
  	}
  
  	public static int pow(int base, int index) {
  		if (index == 0) {
  			return 1;
  		} else if (index % 2 == 0) {
  			return pow(base * base, index / 2);
  		} else {
  			return base * pow(base * base, ((index - 1) / 2));
  		}
  	}
  
  	public static long pow(long base, long index) {
  		if (index == 0) {
  			return 1;
  		} else if (index % 2 == 0) {
  			return pow(base * base, index / 2);
  		} else {
  			return base * pow(base * base, ((index - 1) / 2));
  		}
  	}
  
  	static class pair {
  		long first;
  		long second;
  
  		pair() {
  			this.first = 0l;
  			this.second = 0l;
  		}
  
  		pair(long first, long second) {
  			this.first = first;
  			this.second = second;
  		}
  
  		void make_pair(long first, long second) {
  			this.first = first;
  			this.second = second;
  		}
  	}
  }