#ifdef Rahul
#include "RAHUL.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define error(...) 42;
#endif
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
const int MOD = (int) 1e9 + 7;
const i64 INF = (i64) 1e18 + 42;

inline int add(int a, int b, int mod = MOD) {
  a += b; return a >= mod ? a - mod : a;
}
inline int sub(int a, int b, int mod = MOD) {
  a -= b; return a < 0 ? a + mod : a;
}
inline int mul(int a, int b, int mod = MOD) {
  return int((long long) a * b % mod);
}
inline int mpow(int base, long long ex, int mod = MOD) {
  int res = 1;
  for (; ex > 0; ex >>= 1) {
    if (ex & 1) res = mul(res, base, mod);
    base = mul(base, base, mod);
  }
  return res;
}
inline int inv(int a, int mod = MOD) {
  return mpow(a, mod - 2, mod);
}
inline int mdiv(int a, int b, int mod = MOD) {
  return mul(a, mpow(b, mod - 2,  mod));
}
inline void adds(int &a, int b, int mod = MOD) {
  a += b; if (a >= mod) a -= mod;
}
inline void subs(int &a, int b, int mod = MOD) {
  a -= b; if (a < 0) a += mod;
}
inline void muls(int &a, int b, int mod = MOD) {
  a = int((long long) a * b % mod);
}
inline void mdivs(int &a, int b, int mod = MOD) {
  a = mdiv(a, b, mod);
}

vector<int> fac, ifac;
void Prep(int nax = 1e6 + 40) {
  fac.resize(nax);
  ifac.resize(nax);
  fac[0] = 1;
  for (int i = 1; i < nax; ++i) fac[i] = mul(i, fac[i - 1]);
  ifac[nax - 1] = inv(fac[nax - 1]);
  for (int i = nax - 1; i > 0; --i) ifac[i - 1] = mul(i, ifac[i]);
}
inline int Ncr(int n, int r) {
  if (n < r || r < 0 || n < 0) return 0;
  return mul(fac[n], mul(ifac[n - r], ifac[r]));
}

int main() {
  cin.tie(nullptr) -> sync_with_stdio(false);
  Prep();
  int n; cin >> n;
  vector<int> a(n);
  i64 s = 0;
  for (int &x : a) cin >> x, s += x;
  if (s % n) kek(0);
  int m = s / n;
  array<int, 3> b {};
  for (int x : a) {
    if (x < m) ++b[0];
    else if (x > m) ++b[1];
    else ++b[2];
  }
  if (b[2] == n) kek(1);
  if (b[0] == 1 || b[1] == 1) {
    int ans = fac[n];
    map<int,int> cnt;
    for (int x : a) {
      cnt[x]++;
    }
    for (auto &[k, v] : cnt) {
      muls(ans, ifac[v]);
    }
    kek(ans);
  }
  int ans = mul(fac[b[0]], fac[b[1]]);
  muls(ans, 2);
  map<int,int> cnt;
  for (int x : a) {
    cnt[x]++;
  }
  for (auto &[k, v] : cnt) if (k != m) {
    muls(ans, ifac[v]);
  }
  muls(ans, Ncr(n, b[2]));
  kek(ans);
} 