#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; constexpr int INF = 1001001001; constexpr int mod = 1000000007; // constexpr int mod = 998244353; template inline bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } template inline bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } struct mint { int x; mint() : x(0) {} mint(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} mint& operator+=(const mint& p){ if((x += p.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint& p){ if((x -= p.x) < 0) x += mod; return *this; } mint& operator*=(const mint& p){ x = (int)(1LL * x * p.x % mod); return *this; } mint& operator/=(const mint& p){ *this *= p.inverse(); return *this; } mint operator-() const { return mint(-x); } mint operator+(const mint& p) const { return mint(*this) += p; } mint operator-(const mint& p) const { return mint(*this) -= p; } mint operator*(const mint& p) const { return mint(*this) *= p; } mint operator/(const mint& p) const { return mint(*this) /= p; } bool operator==(const mint& p) const { return x == p.x; } bool operator!=(const mint& p) const { return x != p.x; } mint pow(int64_t n) const { mint res = 1, mul = x; while(n > 0){ if(n & 1) res *= mul; mul *= mul; n >>= 1; } return res; } // x^(a^b) // warning : x と mod は互いに素 // x % mod == 0 かつ a > 0 はこれを呼び出さずに 0 を返すように処理 mint pow2(int64_t a, int64_t b) const { if(b == 0) return *this; if((a %= mod - 1) == 0) return mint(1); int64_t n = 1; while(b > 0){ if(b & 1) (n *= a) %= mod - 1; (a *= a) %= mod - 1; b >>= 1; } return pow(n); } mint inverse() const { return pow(mod - 2); } friend ostream& operator<<(ostream& os, const mint& p){ return os << p.x; } friend istream& operator>>(istream& is, mint& p){ int64_t val; is >> val; p = mint(val); return is; } }; mint dp[1000005]; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int K, S = 0; cin >> K; vector C(K); for(int i = 0; i < K; ++i){ cin >> C[i]; S += C[i]; } vector div; for(int i = 1; i * i <= S; ++i){ if(S % i == 0){ div.emplace_back(i); if(i * i != S) div.emplace_back(S / i); } } sort(begin(div), end(div)); vector fact(S + 1, 1), ifact(S + 1, 1); for(int i = 1; i <= S; ++i) fact[i] = fact[i - 1] * i; ifact[S] = fact[S].inverse(); for(int i = S; i > 0; --i) ifact[i - 1] = ifact[i] * i; int N = div.size(); mint ans = 0; for(int i = 0; i < N; ++i){ if(div[i] < K) continue; bool ok = true; int sum = 0, cnt = S / div[i]; mint way = fact[div[i]]; for(int j = 0; j < K; ++j){ if(C[j] % cnt != 0) { ok = false; break; } int per = C[j] / cnt; sum += per; way *= ifact[per]; } ok &= sum == div[i]; if(!ok) continue; dp[div[i]] += way; ans += dp[div[i]] / div[i]; for(int j = i + 1; j < N; ++j){ if(div[j] % div[i] == 0) dp[div[j]] -= dp[div[i]]; } } cout << ans << endl; return 0; }