1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <bits/stdc++.h>

using namespace std;

#define JOIN_(X, Y) X##Y
#define JOIN(X, Y) JOIN_(X, Y)
#define TMP JOIN(tmp, __LINE__)
#define PB push_back
#define SZ(x) int((x).size())
#define REP(i, n) for (int i = 0, TMP = (n); i < TMP; ++i)
#define FOR(i, a, b) for (int i = (a), TMP = (b); i <= TMP; ++i)
#define FORD(i, a, b) for (int i = (a), TMP = (b); i >= TMP; --i)

#ifdef DEBUG
#define DEB(x) (cerr << x)
#else
#define DEB(x)
#endif

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;

const int MAX = 5000;
// const int MAX = 20;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "vector[";
    for (const auto &e : v) {
        os << e << ", ";
    }
    os << "]";
    return os;
}

void inline one() {
    int n;
    cin >> n;
    vi a(n + 1);
    FOR(i, 1, n) { cin >> a[i]; }
    sort(a.begin() + 1, a.end());
    vi dp(MAX + 1);
    // vi sum(n + 1);
    dp[0] = 1;
    FOR(i, 1, n) {
        DEB("i=" << i << "\n");
        DEB("dp=" << dp << "\n");
        vi next_dp = dp;
        FOR(j, a[i] - 1, MAX) {
            int next_j = min(j + a[i], MAX);
            next_dp[next_j] = (dp[j] + next_dp[next_j]) % MOD;
        }
        dp.swap(next_dp);
    }
    int result = 0;
    FOR(i, 1, MAX) { result = (result + dp[i]) % MOD; }
    cout << result << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // int z; cin >> z; while(z--)
    one();
}