#include <iostream>
#include <map>

constexpr int N = 100005;
constexpr int p = 1000000007;

int mul(int x, int y) { return (long long)x * y % p; }
int power(int x, int y) { int ans = 1; for (; y; y >>= 1) { if (y & 1) ans = mul(ans, x); x = mul(x, x); } return ans; }

int n;
int a[N];
int fac[N], inv[N];
std::map<int, int> cnt;

int main() {
    std::ios::sync_with_stdio(false), std::cin.tie(nullptr);
    std::cin >> n;
    long long sum = 0;
    for (int i = 1; i <= n; ++i) std::cin >> a[i], sum += a[i];
    if (sum % n) return std::cout << "0\n", 0;
    fac[0] = 1;
    for (int i = 1; i <= n; ++i) fac[i] = mul(fac[i - 1], i);
    inv[n] = power(fac[n], p - 2);
    for (int i = n; i; --i) inv[i - 1] = mul(inv[i], i);
    int x = sum / n;
    int cnt0 = 0, cntg = 0, cntl = 0;
    for (int i = 1; i <= n; ++i) {
        if (a[i] == x) ++cnt0;
        else if (a[i] > x) ++cntg;
        else ++cntl;
        ++cnt[a[i]];
    }
    if (!cntg && !cntl) return std::cout << "1\n", 0;
    int ansg = fac[cntg], ansl = fac[cntl];
    for (auto [i, k] : cnt)
        if (i > x) ansg = mul(ansg, inv[k]);
        else if (i < x) ansl = mul(ansl, inv[k]);
    if (cntg == 1) return std::cout << mul(mul(fac[n], mul(inv[cnt0], inv[n - cnt0])), mul(ansl, n - cnt0)) << '\n', 0;
    if (cntl == 1) return std::cout << mul(mul(fac[n], mul(inv[cnt0], inv[n - cnt0])), mul(ansg, n - cnt0)) << '\n', 0;
    std::cout << mul(mul(mul(fac[n], mul(inv[cnt0], inv[n - cnt0])), mul(ansg, ansl)), 2) << '\n';
    return 0;
}
