#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb emplace_back
#define mp make_pair
#define sqr(n) ((n)*(n))
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
#define precision(a) setiosflags(ios::fixed) << setprecision(a)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef double db;

template <typename T> inline char read(T& x) {
    x = 0; T fg = 1; char ch = getchar();
    while (!isdigit(ch)) { if (ch == '-') fg = -1; ch = getchar(); }
    while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ '0'), ch = getchar();
    x = fg * x; return ch;
}
template <typename T, typename... Args> inline void read(T& x, Args &... args) { read(x), read(args...); }
template <typename T> inline void write(T x) {
    int len = 0; char c[40]; if (x < 0) putchar('-'), x = -x;
    do { ++len; c[len] = x % 10 + '0'; } while (x /= 10);
    for (int i = len; i >= 1; i--) putchar(c[i]);
}
template <typename T, typename... Args> inline void write(T& x, Args &... args) { write(x), write(args...); }

template<class T1, class T2> bool umin(T1& a, T2 b) { return a > b ? (a = b, true) : false; }
template<class T1, class T2> bool umax(T1& a, T2 b) { return a < b ? (a = b, true) : false; }
template<class T> void clear(T& a) { T().swap(a); }

const int N = 1e5 + 5, mod = 1e9 + 7;

int n, m, _, k, cas;
ll fac[N], facinv[N], inv[N];
int a[N];

void init(int n) {
    fac[0] = fac[1] = facinv[0] = facinv[1] = inv[0] = inv[1] = 1;
    rep(i, 2, n)
        fac[i] = fac[i - 1] * i % mod,
        inv[i] = inv[mod % i] * (mod - mod / i) % mod,
        facinv[i] = facinv[i - 1] * inv[i] % mod;
}

int main() {
    IOS; cin >> n; init(n); ll s = 0;
    rep(i, 1, n) cin >> a[i], s += a[i];
    if (s % n) return cout << 0, 0;
    sort(a + 1, a + 1 + n); s /= n;
    int l = lower_bound(a + 1, a + 1 + n, s) - a, r = upper_bound(a + 1, a + 1 + n, s) - a - 1;
    if (l == 1 && r == n) return cout << 1, 0;
    ll x = fac[l - 1], y = fac[n - r], ans = fac[n] * facinv[r - l + 1] % mod * facinv[n - r + l - 1] % mod;
    for (int i = 1, c = 0; i < l; ++i, ++c) if (a[i] != a[i + 1]) x = x * facinv[++c] % mod, c = -1;
    for (int i = n, c = 0; i > r; --i, ++c) if (a[i] != a[i - 1]) y = y * facinv[++c] % mod, c = -1;
    if (l == 2) cout << ans * y % mod * (n - r + l - 1) % mod;
    else if (r == n - 1) cout << ans * x % mod * l % mod;
    else cout << ans * x % mod * y % mod * 2 % mod;
    return 0;
}