#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = (1e5 + 20), INF = 0x3f3f3f3f3f3f3f3f, mod = 1e9 + 7;
int a[N];
map<int, int> mp;
vector<int> source, sink;
int ksm(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1) res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}
int fac[N], inv[N];
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    fac[0] = 1;
    for (int i = 1; i < N; i++) fac[i] = fac[i - 1] * i % mod;
    inv[N - 1] = ksm(fac[N - 1], mod - 2);
    for (int i = N - 2; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % mod;

    int n;
    cin >> n;
    int sum = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    if (sum % n) {
        cout << 0 << "\n";
    } else {
        int x = sum / n;
        int cntsou = 0, cntsink = 0;
        for (int i = 1; i <= n; i++) {
            if (a[i] > x) {
                cntsou++;
                if (!mp[a[i]]) source.push_back(a[i]);
            } else if (a[i] < x) {
                cntsink++;
                if (!mp[a[i]]) sink.push_back(a[i]);
            }
            ++mp[a[i]];
        }
        if (cntsou <= 1 || cntsink <= 1) {
            int ans = fac[n];
            for (auto x : mp) {
                ans = ans * inv[x.second] % mod;
            }
            cout << ans << "\n";
        } else {
            int res1 = fac[cntsou];
            for (auto x : source) res1 = res1 * inv[mp[x]] % mod;

            int res2 = fac[cntsink];
            for (auto x : sink) res2 = res2 * inv[mp[x]] % mod;

            int res3 = fac[n] % mod * inv[cntsink + cntsou] % mod *
                       inv[n - cntsink - cntsou] % mod;
            int ans = res1 * res2 % mod * res3 % mod * 2 % mod;
            cout << ans << "\n";
        }
    }

    return 0;
}