#include <bits/stdc++.h>
using namespace std;
         
#define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define eb emplace_back
#define ll long long
#define ld long double
#define vll vector<ll>
#define infl LONG_LONG_MAX
#define infd LDBL_MAX
#define F first
#define S second
#define pll pair<ll,ll> 
#define G(a,b) get<a>(b)
#define ALL(v) v.begin(),v.end()
#define MP make_pair
#define MT make_tuple
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(ll i=(b-1);i>=a;i--)    
#define endl "\n"
#define nl cout<<"\n";
#define pr(x) cout<<x;
#define pr1(x) cout<<x<<" ";
#define pr2(x,y) cout<<x<<" "<<y;
#define sz(x) (ll)x.size() 
#define ara cout<<"ara-ara\n"; 
const ld PI=3.1415926535897932384626433;


#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 <<"\n";
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N=1e5+5,p=1e9+7;
ll n,a[N],fac[N],faci[N];

ll pow_mod_p(ll a,ll b)
{
   a=a%p;
   ll res=1;
   while(b>0)
   {
     if(b&1) res=(res*a)%p;
     b=b>>1;
     a=(a*a)%p;
   }
   return res;
}

inline ll mod_inv(ll x)
{
   return pow_mod_p(x,p-2);
}

ll Get(vll &v)
{
	ll cnt=sz(v);
	vector<pll>vec;
    vec.eb(v[0],1);
    f(i,1,sz(v))
    {
    	ll val=v[i];
    	if(val==vec.back().F) vec.back().S++;
    	else vec.eb(v[i],1);
    }
    ll res=fac[cnt];
    ll den=1;
    for(auto i : vec) den=(den*faci[i.S])%p;
    res=(res*den)%p;
    return res;
}


ll nCr(ll x,ll y)
{
   if(x<y) return 0;
   if(x==y) return 1;
   ll res=fac[x];
   ll deni=(faci[y]*faci[x-y])%p;
   res=(res*deni)%p;
   return res;
}

void func()
{
	cin>>n;
	ll sm=0;
	f(i,1,n+1) 
	{
		cin>>a[i];
		sm+=a[i];
	}   

	if(sm%n!=0)
	{
		cout<<"0\n";
		return;
	}

    fac[0]=fac[1]=1;
    f(i,2,n+1) fac[i]=(fac[i-1]*i)%p;
    f(i,0,n+1) faci[i]=mod_inv(fac[i]);

    ll d=sm/n;
	vll v1,v2;
	f(i,1,n+1)
	{
		if(a[i]<d) v1.pb(d-a[i]);
		else if(a[i]>d) v2.pb(a[i]-d);
	}

	vector<pll>vec;
	sort(a+1,a+n+1);
	vec.eb(a[1],1);
	f(i,2,n+1)
	{
		if(a[i]==vec.back().F) vec.back().S++;
		else vec.eb(a[i],1);
	} 

	ll den=1;
	for(auto i : vec) den=(den*faci[i.S])%p;
	ll tt=(fac[n]*den)%p;	

	if(v1.empty() && v2.empty())
	{
		cout<<tt<<"\n";
		return;
	}

	sort(ALL(v1));
	sort(ALL(v2));
    
    if(sz(v1)==1 || sz(v2)==1)
    {
    	cout<<tt<<"\n";
    	return;
    }

    /*if(v1[0]!=v1.back() || v2[0]!=v2.back())
    {
    	cout<<"0\n";
    	return;
    }

    cout<<"2\n";*/
    ll ans=(Get(v1)*Get(v2))%p;
    ans=(ans*2)%p;
    ans=(ans*nCr(n,n-sz(v1)-sz(v2)))%p;
    cout<<ans<<"\n";
}



int main() 
{
    fast
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //#endif // ONLINE_JUDGE

    ll ntc=1;
    //cin>>ntc;
     
    f(i,1,ntc+1)
    {
       func();
    }
     
    return 0;
}
