#include <bits/stdc++.h>
using namespace std;

#define ll long long
const int N = 2e5+15;


const int mod = 1e9+7;

int fac[N],inv[N];
int add(int x,int y) {
  return ((x+y)%mod+mod)%mod;
}
int mul(int x,int y) {
  return (ll)x*y%mod;
}
int mypow(int x,int c) {
  int ret = 1;
  while(c>0) {
    if(c&1) {
      ret = mul(ret,x);
    }
    c/=2;
    x = mul(x,x);
  }
  return ret;
}

int gcd(int x,int y) {
  if(x==0) {
    return y;
  }
  return gcd(y%x,x);
}

int combi(int n,int r) {
  if(n<r) {
    return 0;
  }
  return mul(fac[n],mul(inv[r],inv[n-r]));
}

int a[N];

int go(int n,ll g) {
  int ret = 1;
  for(int i=1;i<=n;) {
    int j = i;
    for(j=i;j<=n;++j) {
      if(a[j]!=a[i]) break;
    }
    ret = mul(ret, inv[j-i]);
    i = j;
  }
  return ret;
}

void solve2() {
  int n;
  scanf("%d ", &n);
  ll sum = 0;
  for(int i=1;i<=n;++i) {
    scanf("%d ", &a[i]);
    sum += a[i];
  }
  if(n==1) {
    printf("1\n");
    return;
  }
  if(sum%n!=0) {
    printf("0\n");
    return;
  }
  ll g= sum/n;
  int sm= 0,big = 0;
  sort(a+1,a+n+1);
  for(int i=1;i<=n;++i) {
    if(a[i]<g) {
      ++sm;
    } else if(a[i]>g) {
      ++big;
    }
  }
  int ret;
  if(sm==1 || big==1 || sm==0 || big==0) {
    ret = fac[n];
  } else {
    ret = mul(2,combi(n,sm+big));
    ret = mul(ret, mul(fac[sm],fac[big]));
    ret = mul(ret, fac[n-sm-big]);
  }
  ret = mul(ret,go(n,g));


  printf("%d\n", ret);
}



void init() {
  fac[0] = 1;
  for(int i=1;i<N;++i) {
    fac[i] = mul(fac[i-1],i);
  }
  inv[N-1] = mypow(fac[N-1],mod-2);
  for(int i=N-2;i;--i) {
    inv[i] = mul(inv[i+1],i+1);
    assert(mul(inv[i],fac[i])==1);
  }
  inv[0] = 1;
}

void solve() {
  init();
  // int t;
  // cin>>t;
  // while (t--)
    solve2();
}

inline bool exists_test0 (const std::string& name);
inline bool exists_test1 (const std::string& name);
int main() {
#ifdef LOCAL
  string file_name = "input.txt";
  assert(exists_test0(file_name));
  assert(exists_test1(file_name));
  freopen("input.txt","r",stdin);
#endif
  solve();
  return 0;
}

/*
0. Enough array size? Enough array size? Integer overflow?

1. Think TWICE, Code ONCE!
Are there any counterexamples to your algo?

2. Be careful about the BOUNDARIES!
N=1? P=1? Something about 0?

3. Do not make STUPID MISTAKES!
Time complexity? Memory usage? Precision error?

4. Be careful to use wrong variable.
*/
inline bool exists_test0 (const std::string& name) {
    ifstream f(name.c_str());
    return f.good();
}

inline bool exists_test1 (const std::string& name) {
    if (FILE *file = fopen(name.c_str(), "r")) {
        fclose(file);
        return true;
    } else {
        return false;
    }
}
