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
#include <bits/stdc++.h>
using namespace std;

constexpr int nax = 5000, pax = 5000, sax = 4 * nax, mod = 1e9 + 7;

int n, res, tab[nax], dp[sax + 2];

bool works(const int a, const int b) {
    int v = (a + b) - a;
    if (v == b) --v;
    return v <= a;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n;

    for (int i = 0; i < n; ++i) {
        cin >> tab[i];
    }

    sort(begin(tab), begin(tab) + n);

    dp[0] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = sax + 1; j >= 0; --j) {
            if (works(j, tab[i])) {
                auto& d = dp[min(j + tab[i], sax + 1)];
                d += dp[j];
                if (d >= mod) d -= mod;
            }
        }
    }

    for (int i = 1; i <= sax + 1; ++i) {
        res += dp[i];
        if (res >= mod) res -= mod;
    }

    cout << res << '\n';
}