#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstring>
#define ios             ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define bug(str, x)     cerr << "# " << str << " : " << x << '\n'
#define here(x)         cerr << "here " << x << '\n'

using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
const int inf = 1e9;
int fact[maxn], invfact[maxn];
int a[maxn];
map<int, int> cnt;

int mul(int a, int b){
	return 1ll * a * b % mod;
}

int pwr(int a, int b){
	int res = 1;
	for(; b; b >>= 1){
		if(b & 1){
			res = mul(res, a);
		}
		a = mul(a, a);
	}
	return res;
}

int inv(int a){
	return pwr(a, mod - 2);
}

int C(int a, int b){
	int res = fact[b];
	res = mul(res, invfact[a]);
	res = mul(res, invfact[b - a]);
	return res;
}

int main(){
	ios;
	int n;
	cin >> n;
	fact[0] = 1;
	for(int i = 1; i <= n; i ++){
		fact[i] = mul(fact[i - 1], i);
	}
	for(int i = 0; i <= n; i ++){
		invfact[i] = inv(fact[i]);
	}	
	ll sum = 0;
	for(int i = 0; i < n; i ++){
		cin >> a[i];
		sum += a[i];
		cnt[a[i]] ++;
	}
	if(sum % n){
		return cout << 0, 0;
	}
	int mid = sum / n;
	int src_cnt = 0, sink_cnt = 0;
	int res1 = 1, res2 = 1;
	for(auto u : cnt){
		if(u.first > mid){
			src_cnt += u.second;
			res1 = mul(res1, invfact[u.second]);
		}
		else if(u.first < mid){
			sink_cnt += u.second;
			res2 = mul(res2, invfact[u.second]);
		}
	}
	if(!src_cnt && !sink_cnt){
		return cout << 1, 0;
	}
	int ans = 1;
	if(src_cnt == 1){
		ans = fact[n];
		ans = mul(ans, res2);
		ans = mul(ans, invfact[n - (src_cnt + sink_cnt)]);
	}
	else if(sink_cnt == 1){
		ans = fact[n];
		ans = mul(ans, res1);
		ans = mul(ans, invfact[n - (src_cnt + sink_cnt)]);
	}
	else{
		res1 = mul(res1, fact[src_cnt]);
		res2 = mul(res2, fact[sink_cnt]);
		ans = mul(res1, res2);
		ans = mul(ans, 2);
		ans = mul(ans, C(src_cnt + sink_cnt, n));
	}
	cout << ans << '\n';
}

