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
68
69
70
71
72
73
74
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
typedef vector<int> vi;
#define pb push_back
#define sz size()
typedef pair<int,int> pii;
#define mp make_pair
#define st first
#define nd second
typedef long long ll;
#define INF 1000000001
#define MOD 1000000007
#define ALL(t) t.begin(),t.end()
#define SC(a) scanf("%d", &a)
#define GET(a) int a; SC(a)

#define ISDEBUG 0
#define dprintf(...) if(ISDEBUG) \
{printf("\033[31m"); printf(__VA_ARGS__); printf("\033[0m");}
template <class It> void dptab(It b, It e, const char* f="%2d ") {
	if(ISDEBUG) {
		for(It it=b; it!=e; ++it) dprintf(f, *it); dprintf("\n");
}}

#define MAX_N 5001

ll comb[MAX_N];

int main() {
	GET(n);
	multiset<int> values;
	while(n--) {
		GET(v);
		values.insert(v);
	}
	comb[0] = 1;
	ll used_n;
	ll out = 0;
	ll overall = 0;
	for(auto v : values) {
		ll starters = 0;
		FOR(i,v-1,MAX_N) {
			starters += comb[i];
			starters %= MOD;
		}
		starters += out;
		if(!starters) break;

		overall += starters;
		overall %= MOD;

		out *= 2;
		out %= MOD;

		for(int i=MAX_N-1;i>=v-1;--i) {
			if(comb[i]) {
				if(i+v>=MAX_N) {
					out += comb[i];
					out %= MOD;
				} else {
					comb[i+v] += comb[i];
					comb[i+v] %= MOD;
				}
			}
		}
		dprintf("Used value %d;   %d starters\n", v, (int) starters);
		//dptab(ALL(indicies));
		dptab(comb, comb+20);
	}

	printf("%d\n", (int) overall);
	return 0;
}