#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef uint32_t u32;
typedef uint64_t u64;
typedef pair<int, int> pii;
typedef pair<int, int> point;
#define fi first
#define se second
#define pb(x) push_back(x)
#define SZ(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define rep(i, l, r) for(int i = l; i < r; i++)
typedef long long ll;
const int mod = 998244353;



int main() {
#ifdef local
	freopen("in.txt", "r", stdin);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	const int mod = 1e9 + 7;
	int n;
	cin >> n;
	vector<int> a(n);
	ll tot = 0;
	for(auto &e : a) {
		cin >> e;
		tot += e;
	}
	if(tot % n) {
		cout << "0\n";
		return 0;
	}
	vector<int> fac(n + 1, 1);
	vector<int> ifac(n + 1, 1);
	for(int i = 2; i <= n; i++) {
		fac[i] = (ll) fac[i - 1] * i % mod;
		ifac[i] = (ll) ifac[mod % i] * (mod - mod / i) % mod;
	}
	for(int i = 2; i <= n; i++) {
		ifac[i] = (ll) ifac[i] * ifac[i - 1] % mod;
	}
	auto C = [&](int n, int m) {
		if(n < m || m < 0) return 0ll;
		return (ll) fac[n] * ifac[m] % mod * ifac[n - m] % mod;
	};
	ll avg = tot / n;
	vector<int> l, r;
	int eq = 0;
	for(auto &e : a) {
		if(e > avg) {
			r.push_back(e);
		} else if(e < avg) {
			l.push_back(e);
		} else {
			eq++;
		}
	}
	int ans = 1;
	if(l.size() > 1 && r.size() > 1) {
		ans = 2;
	}
	if(l.size() == 1) {
		r.push_back(l[0]);
		l.clear();
	}
	if(r.size() == 1) {
		l.push_back(r[0]);
		r.clear();
	}
	sort(all(l));
	sort(all(r));
	int a1 = fac[l.size()];
	int a2 = fac[r.size()];
	for(int i = 0, j = 0; i < (int) l.size(); i = j) {
		while(j < (int) l.size() && l[j] == l[i]) {
			j++;
		}
		a1 = (ll) a1 * ifac[j - i] % mod;
	}
	for(int i = 0, j = 0; i < (int) r.size(); i = j) {
		while(j < (int) r.size() && r[j] == r[i]) {
			j++;
		}
		a2 = (ll) a2 * ifac[j - i] % mod;
	}
	int a3 = C(n, eq);
	ans = (ll) ans * a1 % mod;
	ans = (ll) ans * a2 % mod;
	ans = (ll) ans * a3 % mod;
	cout << ans << '\n';
	return 0;
}
