#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <assert.h>
using namespace std;
#define int long long 
const int N = 1e5 + 5, mod = 1e9 + 7;
int a[N];
map<int, int> cnt;
int A[N], invA[N];
int qpow(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1) res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}
void init() {
    A[0] = 1;
    for (int i = 1; i < N; i++) A[i] = A[i - 1] * i % mod;
    invA[N - 1] = qpow(A[N - 1], mod - 2);
    for (int i = N - 2; i >= 0; i--) invA[i] = (invA[i + 1] * (i + 1)) % mod;    
    //for(int i = 0; i < N; i++) assert(invA[i] == qpow(A[i], mod-2));
}
signed main() {
    init();
    int n, x = 0;
    scanf("%lld", &n);
    set<int> S;
    for (int i = 1; i <= n; i++) {
        scanf("%lld", &a[i]);
        S.insert(a[i]);
        cnt[a[i]]++;
        x += a[i];
    }
    if (x % n != 0) {
        printf("0\n");
        return 0;
    }
    x = x / n;
    set<int> Src, Snk;
    int src = 0, snk = 0;
    for (int i = 1; i <= n; i++) {
        if (a[i] < x) {
            Src.insert(a[i]);
            src++;
        } else if (a[i] > x) {
            Snk.insert(a[i]);
            snk++;
        }
    }
    int res = 0;
    if ((src == 1 || snk == 1) || (src == 0 && snk == 0)) {
        res = A[n];
        for (auto x : S) {
            res = res * invA[cnt[x]] % mod;
        }
    } else {
        res = 2 * A[src] % mod * A[snk] % mod;
        //if (n - src - snk != 0) res = res * A[src + snk + 1] % mod * invA[2 * (src + snk) + 1 - n] % mod;
        if (n - src - snk != 0) res = res * A[n] % mod * invA[src + snk] % mod * invA[n - src - snk] % mod;
        for (auto x : Src) {
            res = res * invA[cnt[x]] % mod;
        }
        for (auto x : Snk) {
            res = res * invA[cnt[x]] % mod;
        }
    }
    printf("%lld\n", res);
    return 0;
}