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
79
#include <bits/stdc++.h>
#define PB push_back
#define ST first
#define ND second

//#pragma GCC optimize ("O3")
//#pragma GCC target("tune=native")

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;

const int nax = 300 * 1000 + 10, mod = 1e9 + 7;
int n;
int val[nax];
int nr = 0;
map<int,int>sc;

int T[(1 << 20)][2];
int R;

void upd(int a, int x, int parity) {
	a += R;
	T[a][parity] = (T[a][parity] + x) % mod;
	while(a > 1) {
		a /= 2;
		T[a][parity] = (T[2*a][parity] + T[2*a+1][parity]) % mod;
	}
}

int qr(int a, int b, int parity) {
	a += R; b += R;
	if(a > b) return 0;
	int w = T[a][parity];
	if(a != b) w = (w + T[b][parity]) % mod;
	while(a / 2 != b / 2) {
		if(a % 2 == 0) w = (w + T[a^1][parity]) % mod;
		if(b % 2 == 1) w = (w + T[b^1][parity]) % mod;
		a /= 2;
		b /= 2;
	}
	return w;
}



int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	sc[0];
	int sum = 0;
	for(int i = 1; i <= n; ++i) {
		cin >> val[i];
		sum = (sum + val[i]) % mod;
		sc[sum];
	}
	for(auto &it : sc) it.ND = nr++;
	R = 1;
	while(R < nr) R *= 2;
	upd(sc[0], 1, 0);
	sum = 0;
	int ans = 0;
	for(int i = 1; i <= n; ++i) {
		sum = (sum + val[i]) % mod;
		int x = sc[sum];
		int dp = (qr(0, x, sum & 1) + qr(x + 1, nr - 1, 1^(sum&1))) % mod;
		ans = dp;
		upd(x, dp, sum & 1);
	}
	cout << ans;
}