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
80
#include <bits/stdc++.h>
#define ll long long

using namespace std;

ll mod = 1e9+7;
ll treeSize;

ll pot(ll x){
	ll tmp = 1;
	while(x){
		x/=2;
		tmp*=2;
	}
	return tmp;
}

struct node{
	node *l, *r;
	ll val;
	node(ll v){
		val = v;
		l = nullptr;
		r = nullptr;
	}
};

void update(ll a, ll v, node *pt, ll l=0, ll r = treeSize-1){
	pt->val+=v;	
	pt->val%=mod;
	if(l==r) return;
	ll mid = (l+r)/2;
	if(pt->l==nullptr) pt->l = new node(0);
	if(pt->r==nullptr) pt->r = new node(0);
	if(a<=mid) update(a, v, pt->l, l, mid);
	if(a>mid) update(a, v, pt->r, mid+1, r);
}

ll qur(ll a, ll b, node *pt, ll q=0, ll r=treeSize-1){ 
	if(pt==nullptr) return 0;
	if(a==q&&b==r){
		//cout<<a<<" "<<b<<" "<<pt->val<<'\n';
		return pt->val;
	}
	ll mid = (q+r)/2;
	ll out = 0;
	if(a<=mid) out += qur(a, min(mid, b), pt->l, q, mid);
	if(b>mid) out += qur(max(a, mid+1), b, pt->r, mid+1, r);
	return out%mod;
}

int main(){
	ios_base::sync_with_stdio(0);
	ll n; cin>>n;
	treeSize = pot(mod);
	node *odd = new node(0), *even = new node(0);
	update(0, 1, even);
	ll pref = 0;
	ll wyn = 0;
	for(ll i = 0; i < n; i++){
		ll a; cin>>a;
		pref+=a;	
		pref%=mod;
		ll tmp = 0;
		if(pref%2){
			tmp+=qur(0, pref, odd);
			tmp+=qur(pref+1, mod, even);
			update(pref, tmp, odd);
		}else{
			tmp+=qur(0, pref, even);
			//cout<<i<<" "<<tmp<<'\n';
			tmp+=qur(pref+1, mod, odd);
			update(pref, tmp, even);
		}
		//cout<<tmp<<'\n';
		if(i==n-1) wyn = tmp%mod;
	}
	cout<<wyn<<'\n';
	return 0;
}