#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define si short int
#define speed ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pill pair<ll,ll>
#define f first
#define s second
#define pilc pair<ll,char>
#define all(a) (a).begin(),(a).end()
#define rep(s,e,step) for(int i = (s); i < (e) ; i += step)
#define vrep(s,e,step) for(int j = (s); j < (e) ; j += step)
#define ex exit(0) 
#define sz(a) (ll)(a).size()
#define triple pair<pill, ll>
#define pinode pair<node*, node*>
#define quadra pair<pill, pill>
#define ld long double
using namespace std;
 
const ll N = 2e5 + 3;
const ll big = 1e14;
const ll hsh2 = 1964325029 ;
const long long mod = 1e9 + 7;
const long double EPS = 1e-20;
const ll block = 1e7;
const ll shift = 2e3;
const ld pi = acos(-1.0);

ll n;
ll a[N];
ll f[N];

ll bp(ll a, ll b) {
	ll c = 1ll;
	while(b) {
		if(b&1ll)
			c = c * a % mod;
		b >>= 1ll;
		a = a * a % mod;
	}
	return c;
}

int main() {
	speed;
	cin >> n;
	f[0] = 1ll;
	for(ll i = 1; i < N; i++) 
		f[i] = f[i - 1] * i % mod;
	ll s = 0;
	for(int i = 1; i <= n; i++)
		cin >> a[i], s += a[i];
	if(s % n) cout << 0, ex;
	s /= n;	
	ll cnt1 = 0, cnt2 = 0, cnt3 = 0;
	for(int i = 1; i <= n; i++) {
	 	cnt1 += (a[i] > s);
	 	cnt2 += (a[i] < s);
	 	cnt3 += (a[i] == s);
	}
	if(cnt1 <= 1 || cnt2 <= 1) {
	    map<ll, ll> x;
	    for(int i = 1; i <= n; i++)
	    	x[a[i]]++;
		ll ans = f[n];
		for(auto u : x)
			ans = (ans * bp(f[u.s], mod - 2)) % mod;	
		cout << ans << '\n', ex;	
	}
	ll ans = 0;
	ll inv1 = 1ll, inv2 = 1ll;
	map<ll, ll> x[2];
	for(int i = 1; i <= n; i++) {
		if(a[i] > s)
			x[0][a[i]]++;
		if(a[i] < s)
			x[1][a[i]]++;
	}
	for(auto u : x[0])
		inv1 = inv1 * f[u.s] % mod;
	for(auto u : x[1])
		inv2 = inv2 * f[u.s] % mod;
	inv1 = bp(inv1, mod - 2), inv2 = bp(inv2, mod - 2);	
	ll h = f[n] * bp(f[cnt1 + cnt2] * f[n - cnt1 - cnt2] % mod, mod - 2) % mod; 
	h = h * f[cnt1] % mod * f[cnt2] % mod;
	cout << 2ll * h % mod * inv1 % mod * inv2 % mod;
}
/*
4
4 6 1 9
2 5 3 2 
*/