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
75
76
77
78
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef double K;
constexpr int INF = 0x3f3f3f3f;

#define FOR(i, b, e) for(int i = (b); i < (e); i++)
#define TRAV(x, a) for(auto &x: (a))
#define SZ(x) ((int)(x).size())
#define PB push_back
#define X first
#define Y second

constexpr int mod = 1e9 + 7;
constexpr int T = 1 << 20;

ii tree[T * 2 + 5];
int shf;
vi ids;

ii ask(int l, int r) {
	l = lower_bound(ids.begin(), ids.end(), l) - ids.begin();
	r = lower_bound(ids.begin(), ids.end(), r) - ids.begin();
	ll a = 0, b = 0;
	for(l += T, r += T; l <= r; l >>= 1, r >>= 1) {
		if(l & 1) a += tree[l].X, b += tree[l].Y, l++;
		if((r & 1) ^ 1) a += tree[r].X, b += tree[r].Y, r--;
	}
	return {a % mod, b % mod};
}

void add(int v, int val) {
	bool flag = v & 1;
	v = lower_bound(ids.begin(), ids.end(), v) - ids.begin();
	if(flag) for(v += T; v; v >>= 1) tree[v].Y = (tree[v].Y + val) % mod;
	else for(v += T; v; v >>= 1) tree[v].X = (tree[v].X + val) % mod;
}

int ile() {
	ii ask1 = ask(0, shf - 1);
	ii ask2 = ask(shf, mod - 1);
	if(shf & 1) return (ask1.X + ask2.Y) % mod;
	return (ask1.Y + ask2.X) % mod;
}

void solve() {
	int n;
	cin >> n;
	vi vec(n);
	TRAV(x, vec) cin >> x;
	ids = {0, mod - 1};
	TRAV(x, vec) shf = (shf + mod - x) % mod, ids.PB(shf), ids.PB(shf - 1);
	sort(ids.begin(), ids.end());
	ids.erase(unique(ids.begin(), ids.end()), ids.end());
	shf = 0;
	add(0, 1);
	FOR(i, 0, n) {
		shf = (shf + mod - vec[i]) % mod;
		if(i + 1 == n) cout << ile() << '\n';
		else add(shf, ile());
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	// int tt; cin >> tt;
	// FOR(te, 0, tt) {
	// 	// cout << "Case #" << te + 1 << ": ";
	// 	solve();
	// }
	solve();
	return 0;
}