#include <bits/stdc++.h>

using namespace std;

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<uint, uint> puu;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<uint> vu;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;
typedef vector<puu> vpuu;
typedef vector<pll> vpll;
typedef vector<pull> vpull;
typedef vector<string> vstr;
typedef vector<double> vdbl;
typedef vector<ldbl> vldbl;
#define pb push_back
#define ppb pop_back
#define pfr push_front
#define ppfr pop_front
#define emp emplace
#define empb emplace_back
#define be begin
#define rbe rbegin
#define all(x) (x).be(), (x).end()
#define rall(x) (x).rbe(), (x).rend()
#define fir first
#define sec second
#define mkp make_pair
#define brif(cond) if (cond) break
#define ctif(cond) if (cond) continue
#define retif(cond) if (cond) return
void canhazfast() {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a%b) : a;}
template<typename T> T extgcd(T a, T b, T &x, T &y)
{
    T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
    while (b) {
        T q = a/b; a %= b; swap(a, b);
        x0 -= q*x1; swap(x0, x1);
        y0 -= q*y1; swap(y0, y1);
    }
    x = x0; y = y0; return a;
}
int ctz(uint x) {return __builtin_ctz(x);}
int ctzll(ull x) {return __builtin_ctzll(x);}
int clz(uint x) {return __builtin_clz(x);}
int clzll(ull x) {return __builtin_clzll(x);}
int popcnt(uint x) {return __builtin_popcount(x);}
int popcntll(ull x) {return __builtin_popcountll(x);}
int bsr(uint x) {return 31^clz(x);}
int bsrll(ull x) {return 63^clzll(x);}

#define MOD 1000000007

uint add(uint a, uint b) { return a+b < MOD ? a+b : a+b-MOD; }
uint sub(uint a, uint b) { return a < b ? a+MOD-b : a-b; }
uint mul(uint a, uint b) { return (ull)a*b%MOD; }
uint sqr(uint a) { return mul(a, a); }

uint modpow(uint b, uint e)
{
    uint r = 1;
    for (; e; e >>= 1) {
        if (e&1) r = mul(r, b);
        b = sqr(b);
    }
    return r;
}

uint modpowll(uint b, ull e)
{
    uint r = 1;
    for (; e; e >>= 1) {
        if (e&1) r = mul(r, b);
        b = sqr(b);
    }
    return r;
}

uint modinv(uint n) { return modpow(n, MOD-2); }
uint moddiv(uint n, uint d) { return mul(n, modinv(d)); }

#define N 100016

int a[N];
uint fac[N];

uint binom(int n, int k)
{
    return moddiv(fac[n], mul(fac[k], fac[n-k]));
}

uint multinom(const vi &f)
{
    int n = 0;
    uint res = 1;
    for (int k : f) {
        n += k;
        res = mul(res, fac[k]);
    }
    return moddiv(fac[n], res);
}

int main()
{
    canhazfast();

    int n, avg, kz = 0, kmi = 0, kpl = 0;
    ll s = 0;
    vi fmi, fpl;
    uint ans;

    cin >> n;
    fac[0] = fac[1] = 1;
    for (int i = 2; i <= n; ++i) fac[i] = mul(fac[i-1], i);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        s += a[i];
    }
    retif(s%n) cout << "0\n", 0;
    avg = s/n;
    sort(a, a+n);
    for (int i = 0, j = 0; i < n; i = j) {
        while (j < n && a[j] == a[i]) ++j;
        int k = j-i;
        if (a[i] < avg) fmi.pb(k), kmi += k;
        else if (a[i] > avg) fpl.pb(k), kpl += k;
        else kz = k;
    }
    if (kmi <= 1 || kpl <= 1) {
        for (int k : fmi) fpl.pb(k);
        fpl.pb(kz);
        ans = multinom(fpl);
    } else {
        ans = mul(multinom(fmi), multinom(fpl));
        ans = mul(ans, binom(n, kz));
        ans = add(ans, ans);
    }
    cout << ans << '\n';

    return 0;
}
