//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")

//#include <immintrin.h>
//#include <emmintrin.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,h,t) for (int i=h;i<=t;i++)
#define dep(i,t,h) for (int i=t;i>=h;i--)
#define ll long long
#define me(x) memset(x,0,sizeof(x))
#define IL inline
#define rint register int
inline ll rd(){
	ll x=0;char c=getchar();bool f=0;
	while(!isdigit(c)){if(c=='-')f=1;c=getchar();}
	while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
	return f?-x:x;
}
char ss[1<<24],*A=ss,*B=ss;
IL char gc()
{
	return A==B&&(B=(A=ss)+fread(ss,1,1<<24,stdin),A==B)?EOF:*A++;
}
template<class T>void maxa(T &x,T y)
{
	if (y>x) x=y;
}
template<class T>void mina(T &x,T y)
{
	if (y<x) x=y;
}
template<class T>void read(T &x)
{
	int f=1,c; while (c=gc(),c<48||c>57) if (c=='-') f=-1; x=(c^48);
	while(c=gc(),c>47&&c<58) x=x*10+(c^48); x*=f;
}
const int mo=1e9+7;
struct re{
	int a,b,c;
};
const int N=1e6;
int a[N];
ll ans=0;
int n;
ll AA(int x,int y)
{  
	ll ans=1;
	dep(i,x,x-y+1) ans=ans*i%mo;
	return ans;
}
map<int,int> M;
ll fsp(int x,int y)
{
	if (y==1) return x;
	ll ans=fsp(x,y/2);
	ans=ans*ans%mo;
	if (y%2==1) ans=ans*x%mo;
	return ans; 
}
int main()
{
   ios::sync_with_stdio(false);
   cin>>n;
   rep(i,1,n) cin>>a[i]; 
   rep(i,1,n) ans+=a[i];
   if (ans%n!=0)
   {
   	cout<<0<<endl;
   } else
   {
   	ans/=n;
   	int ans1=0,ans2=0,ans3=0;
   	ll t=1,t2=1;
   	rep(i,1,n)
   	{
   	  if (a[i]<ans) ans1++;
   	  if (a[i]==ans) ans2++;
   	  if (a[i]>ans) ans3++;
   	  M[a[i]]++;
    }
    if (min(ans1,ans3)>1)
    {
      t=1ll*AA(n,ans2)*AA(ans1,ans1)%mo*AA(ans3,ans3)%mo;
      t=t*2%mo;
    } else
    {
    	t=AA(n,n);
    }
	rep(i,1,n)
    {
      if(M[a[i]])t2=t2*AA(M[a[i]],M[a[i]])%mo;
      M[a[i]]=0;
    } 
    t=t*fsp(t2,mo-2)%mo; 
	cout<<t<<endl;
   }
   return 0;
}


