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
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>

using namespace std;

const int64_t P = 1000000007;

int main () {
	int n;
	scanf("%d", &n);
	vector<int64_t> bags;
	bags.reserve(n + 4);
	for (int i = 0; i < n; ++i) {
		int x;
		scanf("%d", &x);
		bags.push_back(x);
	}
	sort(bags.begin(), bags.end());
	vector<int64_t> sets(5000, 0);
	sets[0] = 1;
	int64_t big = 0;
	for (int i = 0; i < n; ++i) {
		int x = bags[i];
		int64_t old_big = big;
		vector<int64_t> deltas(5000, 0);
		for (int j = x - 1; j < 5000; ++j) {
			int res = j + x;
			if (res >= 5000) {
				big = (big + sets[j]) % P;
			}
			else {
				deltas[res] = (deltas[res] + sets[j]) % P;
			}
		}
		big = (big + old_big) % P;
		for (int j = 0; j < 5000; ++j) {
			sets[j] = (sets[j] + deltas[j]) % P;
		}
	}
	for (int i = 1; i < 5000; ++i) {
		big = (big + sets[i]) % P;
	}
	printf("%lld\n", big);
	return 0;
}