#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define endl '\n'
#define line cout<<"--------------------------"<<endl
#define dd(x) cout<<#x<<" = "<<x<<' '
#define sz(v) (ll)v.size()
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.rbegin(),v.rend())
#define all(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mx=2e5+5; 
void yes() {cout<<"Yes"<<endl; }
ll ara[mx]; 
ll facto[mx],invfacto[mx]; 
void pre()
{
    facto[0]=1; 
    for(ll i=1;i<mx;i++) facto[i]=(facto[i-1]*i)%mod; 
    invfacto[0]=1; 
    invfacto[1]=1; 
    for(ll i=2;i<mx;i++)
    {
        invfacto[i]=mod-(mod/i)*invfacto[mod%i]%mod;  ///pre calculate mod inverse i
    }
    for(ll i=1;i<mx;i++) invfacto[i]=(invfacto[i-1]*invfacto[i])%mod; ///precalculate inverse factorial 
}
ll ncr(ll n, ll r)
{
    if(r>n) return 0; 
    ll ans=facto[n]*invfacto[n-r]; 
    ans%=mod; 
    ans=(ans*invfacto[r])%mod; 
    return ans; 
}
int main()
{
   fast;
    pre();
    ll n; 
    cin>>n; 
    ll sum=0; 
    for(ll i=0;i<n;i++)
    {
      cin>>ara[i]; 
      sum+=ara[i]; 
    }
    if(sum%n) cout<<0<<endl; 
    else 
    {
       sum/=n; 
      ll src=0,snk=0; 
      map<ll,ll> m_src,m_snk,m_nutral; 
      for(ll i=0;i<n;i++)
      {
	 if(ara[i]>sum) src++,m_src[ara[i]]++; 
	 else if(ara[i]<sum) snk++,m_snk[ara[i]]++; 
	 else m_nutral[ara[i]]++;
      }
      if(src<=1 or snk<=1)
      {
	 ll ans=facto[n]; 
	 for(auto x: m_src)
	 {
	    ans=(ans*invfacto[x.second])%mod; 
	 }
	 for(auto x: m_snk)
	 {
	    ans=(ans*invfacto[x.second])%mod; 
	 }
	 for(auto x: m_nutral)
	 {
	    ans=(ans*invfacto[x.second])%mod; 
	 }
	 cout<<ans<<endl; 
      }
      else 
      {
	 ll ans=2*facto[src]; 
	 for(auto x: m_src)
	 {
	    ans=(ans*invfacto[x.second])%mod; 
	 }
	 ans=(ans*facto[snk])%mod; 
	 for(auto x: m_snk)
	 {
	    ans=(ans*invfacto[x.second])%mod; 
	 }
	 ans=(ans*ncr(n,src+snk))%mod; 
	 cout<<ans<<endl; 
      }
    }
}
   
