#include <bits/stdc++.h>
using namespace std;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;

#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define ALL(a,n) a,a+n
#define ALLV(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=int(b); ++i)
#define rFOR(i,a,b) for(int i=a; i>=int(b); --i)

typedef long long ll;
typedef pair<int,int> pii;

const int maxN = 100005;
const int INF = (int)2e9;
const int mod = 1000000007;

ll fact[maxN], finv[maxN];

ll fast_pow(ll a, ll b){
    if(b==0) return 1;
    if(b==1) return a;
    if(b%2) return (a*fast_pow((a*a)%mod, b/2))%mod;
    return fast_pow((a*a)%mod, b/2);
}

void solve(){
    int n; cin >> n;
    vector<int> a(n);
    ll m = 0;
    map<int,int> hist;
    REP(i, n){
        cin >> a[i];
        m += a[i];
        ++hist[a[i]];
    }
    if(m%n){
        cout << "0\n";
        return;
    }
    m /= n;
    ll s = 0;
    ll b = 0;
    ll e = 0;
    for(int x : a){
        if(x<m) ++s;
        else if(x>m) ++b;
        else ++e;
    }

    fact[0] = 1;
    FOR(i, 1, n) fact[i] = (fact[i-1]*i)%mod;
    finv[n] = fast_pow(fact[n], mod-2);
    rFOR(i, n-1, 0) finv[i] = (finv[i+1]*(i+1))%mod;

    ll ans = fact[e];
    if(b<2 || s<2) ans = (ans*fact[s+b]) % mod;
    else{
        ans = (ans*fact[s]) % mod;
        ans = (ans*fact[b]) % mod;
        ans = (ans*2) % mod;
    }

    ans = (ans*fact[n]) % mod;
    ans = (ans*finv[e]) % mod;
    ans = (ans*finv[b+s]) % mod;

    for(pii p : hist){
        ans = (ans*finv[p.second]) % mod;
    }

    cout << ans << "\n";
}

int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}