//int max = 2 147 483 647 (2^31-1)
//ll max = 9 223 372 036 854 775 807 (2^63-1)
#include<bits/stdc++.h>
using namespace std;

#define forn(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
#define MOD 1000000007

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;

//Fast input and output
void fast_io(){
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);}

//Printing pairs and vectors
template<typename A, typename B> ostream& operator<< (ostream &cout, pair<A,B> const &p) {return cout << "(" << p.f << ", " << p.s << ")";}
template<typename A> ostream& operator<< (ostream &cout, vector<A> const&v){
cout << "["; forn(i,(int)v.size()){ if (i) cout << ", "; cout << v[i];} return cout << "]";}

vector<ll>fac(1e7);

ll mpow(ll base, ll exp) {
  ll res = 1;
  while (exp) {
    if (exp % 2 == 1){
        res = (res * base) % MOD;
    }
    exp >>= 1;
    base = (base * base) % MOD;
  }
  return res;
}

ll minv(ll base) {
    return mpow(base, MOD - 2);
}

ll mchoose(int n, int k){
  if(n<k) return 0;

  return ((fac[n]*minv(fac[k]))%MOD*minv(fac[n-k]))%MOD;
}

int main(){
  fast_io();
  fac[0]=1;
  for(int i=1;i<1e7;i++){
    fac[i]=(fac[i-1]*i)%MOD;}
  int n; cin >> n;
  vi a(n); ll tot=0;
  map<int,int>occ;
  forn(i,n){
    cin >> a[i]; tot+=a[i]; occ[a[i]]++;}
  if(tot%n>0){
    cout << 0; return 0;}
  int x=0,y=0,z=0;
  forn(i,n){
    if(a[i]>tot/n) x++;
    if(a[i]<tot/n) y++;
    if(a[i]==tot/n) z++;
  }
  if(x==1 or y==1){
    ll ans=fac[n];
    for(auto i:occ){
      ans=(ans*minv(fac[i.s]))%MOD;}
    cout << ans; return 0;
  }
  if(x==0){
    cout << 1; return 0;}
  ll ans = (((mchoose(n,z)*fac[z])%MOD*fac[y])%MOD*fac[x]*2)%MOD;
  for(auto i:occ){
    ans=(ans*minv(fac[i.s]))%MOD;}
  cout << ans;
}
//code by DanTheMan
