#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#ifdef APURBA
#include "DEBUG_TEMPLATE.h"
#else
#define HERE
#define debug(args...)
#endif
const int N = 1e5 +5;
const ll mod = 1e9+7;
typedef pair<int,int> pii;

ll bigmod(ll a, ll b)
{
    a%=mod;
    ll ans =1;
    while(b>0)
    {
        if(b&1)
        {
            ans = (ans*a)%mod;
        }
        a= (a*a)%mod;
        b>>=1;
    }
    return ans;
}
ll fact[N];
void init()
{
    fact[0]=1;
    for(ll i=1; i<N; i++)
        fact[i]= (fact[i-1]*i)%mod;
}

ll gun(ll x, ll y)
{
    x%=mod;
    y%=mod;
    return (x*y)%mod;
}
ll vag(ll x, ll y)
{
    x%=mod;
    y%=mod;
    return (x* bigmod(y,mod-2))%mod;
}

ll perm(vector<ll>&a)
{
    ll n = a.size();
    if(n==0)
        return 1;
    map<ll,ll>mp;
    for(ll i:a)
    {
        mp[i]++;
    }
    ll ans = fact[n];
    for(auto it:mp)
    {
        if(it.second<=1)
            continue;
        ans = vag(ans, fact[it.second]);
    }
    return ans;
}
ll getncr(ll n, ll r)
{
    if(n<r)
    {
        //cout<<n<<" "<<r<<endl;
        return 0;
    }
    ll up = fact[n];
    ll down = (fact[r]* fact[n-r])%mod;
    return (up * bigmod(down,mod-2))%mod;
}
ll add(ll x, ll y)
{
    if(x>=mod)
        x%=mod;
    if(y>=mod)
        y%=mod;
    x+=y;
    if(x>=mod)
        x-=mod;
    return x;
}
void TEST_CASES(int cas)
{
    ll n;
    cin>>n;
    vector<ll>a(n);
    ll sum =0;
    for(ll i=0; i<n; i++)
    {
        cin>>a[i];
        sum += a[i];
    }
    if(sum%n)
    {
        cout<<"0\n";
        return;
    }
    ll koto = sum/n;
    ll src =0, sink =0, no =0;
    vector<ll>p,q,r;
    for(ll i=0; i<n; i++)
    {
        if(a[i] < koto)
        {
            sink++;
            p.push_back(a[i]);
        }
        else if(a[i]>koto)
        {
            src++;
            q.push_back(a[i]);
        }
        else
        {
            no++;
            r.push_back(a[i]);
        }
    }
    if(src==1 || sink==1)
    {
        cout<<perm(a)<<"\n";
        return;
    }
    if(src==0 || sink==0)
    {
        cout<<perm(a)<<"\n";
        return;
    }
    ll bal = r.size()+1;
    ll ans = perm(r);
    ll sal = gun(perm(p) , perm(q));
    ll jaga= p.size() + q.size() + 1;
    ans = gun(ans , getncr(jaga + r.size()-1 , r.size()));
    ans = gun(ans , sal);
    ans = gun(ans, 2);
    cout<<ans<<"\n";
}

/*
*/

int32_t main()
{
#ifndef APURBA
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#endif
    //freopen("input.txt","r",stdin);
    //freopen("out1.txt","w",stdout);
    init();
    int t=1,cas=0;
    //cin>>t;
    while(t--)
    {
        TEST_CASES(++cas);
    }
    return 0;
}
