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

const ll mod = 1e9 + 7;
ll n, sum, ans;
ll a[100001];
ll fac[100001];
ll inv[100001];

ll quick_pow(ll a, ll k)
{
    ll ans = 1;
    while(k)
    {
        if(k & 1) ans = ans * a % mod;
        a = a * a % mod;
        k >>= 1;
    }
    return ans;
}

ll C(ll n, ll m)
{
    return fac[n] * inv[n - m] % mod * inv[m] % mod;
}

int main()
{
    scanf("%lld", &n);
    fac[0] = 1; for(ll i = 1; i <= n; ++i) fac[i] = fac[i - 1] * i % mod;
    // for(int i = 1; i <= n; ++i) cout << fac[i] << " "; cout << endl;
    inv[n] = quick_pow(fac[n], mod - 2); for(ll i = n - 1; i >= 0; --i) inv[i] = inv[i + 1] * (i + 1) % mod;
    // for(int i = 1; i <= n; ++i) cout << inv[i] << " "; cout << endl;
    for(ll i = 1; i <= n; ++i)
    {
        scanf("%lld", &a[i]);
        sum += a[i];
    }
    // if(n == 1) {puts("1"); return 0;}
    if(sum % n) {puts("0"); return 0;}
    sort(a + 1, a + n + 1);
    sum /= n;
    ll low = 0, equ = 0, high = 0;
    for(ll i = 1; i <= n; ++i)
    {
        if(a[i] < sum) low++;
        else if(a[i] == sum) equ++;
        else high++;
    }
    if(low == 1 || high == 1 || equ == n) ans = fac[n];
    else ans = 2 * fac[low] % mod * fac[high] % mod * C(n, low + high) % mod * fac[equ] % mod;
    ll now = 1;
    for(ll i = 2; i <= n; ++i)
        if(a[i] == a[i - 1]) now++;
        else
        {
            (ans *= inv[now]) %= mod;
            // cout << now << " ";
            now = 1;
        }
        // cout << now << " ";
    (ans *= inv[now]) %= mod;
    printf("%lld\n", ans);
    return 0;
}
