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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll mod = 1000000007; // faster if const

ll modpow(ll b, ll e) {
  ll ans = 1;
  for (; e; b = b * b % mod, e /= 2)
    if (e & 1) ans = ans * b % mod;
  return ans;
}

const int N = 112345;
vl fac(N), ifac(N);

void calc() {
  fac[0] = ifac[0] = 1;
  rep(i,1,N) {
    fac[i] = ll(i) * fac[i-1] % mod;
    ifac[i] = modpow(fac[i], mod-2);
  }
} 

ll nck(ll n, ll k) {
  if (k < 0 || k > n) return 0;
  return ((fac[n] * ifac[k] % mod) * ifac[n-k]) % mod;
}

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  calc();

  int n;
  cin >> n;

  vi a(n);
  rep(i,0,n) cin >> a[i];

  ll sum = accumulate(all(a), 0ll);
  if (sum % n) return cout << 0 << '\n', 0;

  // n | sum

  ll per = sum / n;
  int s = 0, t = 0, m = 0;
  map<int, int> cnt;
  rep(i,0,n) {
    ++cnt[a[i]];
    if (a[i] < per) ++t;
    else if (a[i] > per) ++s;
    else ++m;
  } 

  assert(s+t+m == n);

  ll ans = 2;
  (ans *= fac[s]) %= mod;
  (ans *= fac[t]) %= mod;
  (ans *= fac[m]) %= mod;
  int k = s+t+1;
  (ans *= nck(m+k-1, m)) %= mod;
  if (min(s, t) <= 1) ans = fac[n];
  for (auto [x, y]: cnt) {
    (ans *= ifac[y]) %= mod;
  }
  cout << ans << '\n';
}