#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const LL mod = 1e9+7;

int a[MAXN];
int t, n, k;
map<int, int> mmap;
LL fact[MAXN], factinv[MAXN], inv[MAXN];

void init(int n) {
    fact[0] = fact[1] = inv[0] = inv[1] = factinv[0] = factinv[1] = 1;
    for (int i = 2; i <= n; i++) {
        fact[i] = fact[i-1]*i % mod;
        inv[i] = inv[mod % i]*(mod - mod/i) % mod;
        factinv[i] = factinv[i-1] * inv[i] % mod;
    }
}

LL C(int n, int m) {
    if (n < m) return 0;
    return fact[n] * factinv[m] % mod * factinv[n-m] % mod;
}

int main() {
    scanf("%d", &n);
    init(n);

    LL sum = 0;
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        sum += a[i];
        mmap[a[i]]++;
    }
    if (sum % n != 0) {
        printf("0\n");
        return 0;
    }
    sum /= n;

    if (n == 1) {
        printf("1\n");
        return 0;
    }

    LL ansl = 1, ansr = 1;
    int l = 0, r = 0, cntl = 0, cntr = 0;
    for (auto it : mmap) {
        int key = it.first, value = it.second;
        if (key == sum) continue;
        if (key < sum) l += value, ansl = ansl * C(l, value) % mod;
        else r += value, ansr = ansr * C(r, value) % mod;
    }

    LL ans;
    if (l == 0) ans = ansr;
    else if (r == 0) ans = ansl;
    else if (l == 1) ans = ansr*(r+1) % mod;
    else if (r == 1) ans = ansl*(l+1) % mod;
    else {
        ans = ansl*ansr % mod;
        ans = ans*2 % mod;
    }
    ans = ans * C(n, mmap[sum]) % mod;
    printf("%lld\n", ans);
}
