#include <stdio.h>
#include <algorithm>
#include <vector>
#include <memory.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string.h>
#include <string>
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;

ll fac[100100];
ll inv[100100];
ll modpow(ll a, ll x) {
	if (x == 1) return a;
	ll half = modpow(a, x / 2);
	ll ret = (half*half) % MOD;
	if (x % 2 == 1) ret = (ret * a) % MOD;
	return ret;
}
void init() {
	fac[0] = 1;
	for (int i = 1; i < 100100; i++)
		fac[i] = (fac[i - 1] * i) % MOD;

	inv[100100 - 1] = modpow(fac[100100 - 1], MOD - 2);
	for (int i = 100100 - 2; i >= 0; i--)
		inv[i] = (inv[i + 1] * (i + 1)) % MOD;
}
ll nCk(int n, int k) {
	if (n < k) return 0;
	return (((fac[n] * inv[n - k]) % MOD) * inv[k]) % MOD;
}

int arr[100100];
int cnt[100100];

int main()
{
	int n;
	int scnt, tcnt, acnt;
	ll dups, ans, avg;

	scanf("%d", &n);
	init();

	avg = 0;
	for (int i = 0; i < n; i++){
		scanf("%d", &arr[i]);
		avg += arr[i];
	}
	sort(arr, arr + n);

	if (avg % n != 0){
		printf("0\n");
		return 0;
	}
	avg /= n;

	scnt = 0;
	tcnt = 0;
	acnt = 0;
	dups = 1;
	for (int i = 0; i < n; i++){
		if (arr[i] < avg){
			tcnt++;
			cnt[i] = 1;
			if (i > 0 && arr[i - 1] == arr[i]) {
				cnt[i] += cnt[i - 1];
				dups *= cnt[i];
				dups %= MOD;
			}
		}
		if (arr[i] > avg){
			scnt++;
			cnt[i] = 1;
			if (i > 0 && arr[i - 1] == arr[i]) {
				cnt[i] += cnt[i - 1];
				dups *= cnt[i];
				dups %= MOD;
			}
		}
		if (arr[i] == avg) acnt++;
	}

	if (scnt == 1 || tcnt == 1){
		ans = nCk(n, acnt);
		ans *= fac[scnt + tcnt];
		ans %= MOD;
		ans *= modpow(dups, MOD - 2);
		ans %= MOD;
		printf("%lld\n", ans);
	}
	else if (scnt + tcnt == 0){
		printf("1\n");
	}
	else{
		ans = 2 * nCk(n, acnt) % MOD;
		ans *= fac[scnt];
		ans %= MOD;
		ans *= fac[tcnt];
		ans %= MOD;
		ans *= modpow(dups, MOD - 2);
		ans %= MOD;
		printf("%lld\n", ans);
	}
	return 0;
}
