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
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

constexpr int base = 1<<19;
constexpr int M = 3e5+7;
constexpr int mod = 1e9+7;

int t[M];
int px[M];
int scaled[M];
long long dp[M];
map<int,int>mapa;
long long tree_odd[base<<1];
long long tree_even[base<<1];

void add_odd(int v, int x){
	v += base;
	while(v){
		tree_odd[v] += x;
		if(tree_odd[v] >= mod) tree_odd[v] %= mod;
		v >>= 1;	
	}
}

void add_even(int v, int x){
	v += base;
	while(v){
		tree_even[v] += x;
		if(tree_even[v] >= mod) tree_even[v] %= mod;
		v >>= 1;	
	}
}

long long get_odd(int a, int b){
	long long w = 0;
	a += base-1;
	b += base+1;
	while(b - a > 1){
		if(!(a&1)) w += tree_odd[a+1];
		if(b&1) w += tree_odd[b-1];
		a >>= 1;
		b >>= 1;
	}
	return w;
}

long long get_even(int a, int b){
	long long w = 0;
	a += base-1;
	b += base+1;
	while(b - a > 1){
		if(!(a&1)) w += tree_even[a+1];
		if(b&1) w += tree_even[b-1];
		a >>= 1;
		b >>= 1;
	}
	return w;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int n, x = 0;
	
	cin >> n;
	for(int i=1; i<=n; i++){
		cin >> t[i];
		px[i] = px[i-1] + t[i];
		if(px[i] >= mod) px[i] %= mod;
		mapa[px[i]];
	}
	
	mapa[0];
	
	for(auto ii = mapa.begin(); ii != mapa.end(); ii++)	ii -> second = x++;
	
	for(int i=1; i<=n; i++) scaled[i] = mapa[px[i]];
	
	add_even(0, 1);
	
	for(int i=1; i<=n; i++){
		if(px[i]&1){
			dp[i] = get_odd(0, scaled[i]) + get_even(scaled[i]+1, n);
			if(dp[i] >= mod) dp[i] %= mod;
			add_odd(scaled[i], dp[i]);
		}
		else{
			dp[i] = get_even(0, scaled[i]) + get_odd(scaled[i]+1, n);
			if(dp[i] >= mod) dp[i] %= mod;
			add_even(scaled[i], dp[i]);
		}
	}
	
	cout << dp[n];
	
	return 0;
}