#include <bits/stdc++.h>
using namespace std;

long long P[300010];
constexpr long long mod = 1e9 + 7;

long long fpow(long long a, long long b)
{
    long long z = 1;
    while (b)
    {
        if (b & 1)
            z = z * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return z;
}

long long inv(long long x)
{
    return fpow(x, mod - 2);
}

long long C(int t, int b)
{
    return P[b] * inv(P[t]) % mod * inv(P[b - t]) % mod;
}

long long A(int t, int b)
{
    return P[b] * inv(P[b - t]);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    P[0] = 1;
    for (int i = 1; i < 300005; i++)
    {
        P[i] = P[i - 1] * i % mod;
    }
    int n;
    cin >> n;
    vector<long long> a(n);
    long long sum = 0;
    for (long long &x : a)
    {
        cin >> x;
        sum += x;
    }
    if (sum % n != 0)
    {
        cout << 0 << endl;
        return 0;
    }
    long long ave = sum / n;
    int sso = 0, ssi = 0;
    map<long long, int> so, si;
    for (long long x : a)
    {
        if (x > ave)
        {
            so[x]++;
            sso++;
        }
        else if (x < ave)
        {
            si[x]++;
            ssi++;
        }
    }
    if (sso > 1 && ssi > 1)
    {
        long long ans = P[sso] * P[ssi] % mod;
        for (auto [v, k] : so)
        {
            ans = ans * inv(P[k]) % mod;
        }
        for (auto [v, k] : si)
        {
            ans = ans * inv(P[k]) % mod;
        }
        ans = ans * C(ssi + sso, n) % mod;
        cout << 2*ans%mod << endl;
    }
    else {
        long long ans=P[n]%mod;
        for (auto [v, k] : so)
        {
            ans = ans * inv(P[k]) % mod;
        }
        for (auto [v, k] : si)
        {
            ans = ans * inv(P[k]) % mod;
        }
        ans=ans*inv(P[n-ssi-sso])%mod;
        cout<<ans<<endl;
    }
}