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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include <bits/stdc++.h>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")
#pragma GCC target("sse,sse2,sse3,mmx,abm,tune=native") // for szkopul and sio only
typedef long long lld;
typedef double lf;
typedef long double llf;
typedef pair<int,int> pii;
typedef pair<lld,lld> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define For(i,s,a) for(lld i = (lld)s; i < (lld)a; ++i)
#define rpt(s, it) for(auto it = s.begin(); it != s.end(); ++it)
#define brpt(s, it) for(auto it = s.rend(); it != s.rbegin(); --it)
#define pb push_back
#define eb emplace_back
#define ff first
#define dd second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define make_unique(x) (x).erase( unique(all(x)), (x).end())
#define popcnt(x) __builtin_popcount(x)
#define sz size()
#define time_since duration_cast< milliseconds >(system_clock::now().time_since_epoch())
 
template<typename Ta, typename Tb>
ostream & operator <<(ostream & os, pair<Ta, Tb> x){
	return os << x.ff << " " << x.dd;
}

const int N = 3e5 + 1;
lld c[N], sum[N], dp[N];
int smieszne = 5;
const lld mod = 1e9 + 7;
const int big = 7e6 + 1;
lld tre[2][big];
int lef[2][big], rig[2][big];
int root[2] = {1, 1};

int par;
lld L, R;

lld treget(int w = 1, lld l = 0, lld r = mod + mod - 1) {
	if(L > R)
		return 0;
	if(L > r || R < l)
		return 0;
	if(L <= l && r <= R) {
		return tre[par][w];
	}
	lld mid = (l + r) >> 1ll;
	lld ret = 0;
	if(lef[par][w])
		ret += treget(lef[par][w], l, mid);
	if(rig[par][w])
		ret += treget(rig[par][w], mid + 1, r);
	ret %= mod;
	return ret;
}

lld get(int pos, int prv) {
	lld val = sum[pos];
	val %= (mod * 2);
	lld ret = 0;
	if(val + mod < mod + mod) {
		par = (val & 1ll) ^ 1ll;
		L = val;
		R = val + mod;
		ret = treget();
		par ^= 1;
		L = val + mod + 1;
		R = mod + mod - 1;
		ret += treget();
		L = 0;
		R = val;
		ret += treget();
	} else {
		par = 1ll ^ (val & 1ll);
		L = val;
		R = mod + mod - 1;
		ret = treget();
		R = mod - R + L - 1;
		L = 0;
		ret += treget();
		
		par ^= 1;
		L = R + 1;
		R = val;
		ret += treget();
	}
	return ret % mod;
}

void upd(lld x, int p, lld val, int w = 1, lld l = 0, lld r = mod + mod - 1) {
	tre[p][w] += val;
	if(tre[p][w] >= mod)
		tre[p][w] %= mod;
	//cout << l << " " << r << " updating " << x << " " << tre[p][w] << " " << w << endl;
	if(l == r && l == x) 
		return;
	lld mid = (l + r) >> 1ll;
	if(x <= mid) {
		if(!lef[p][w])
			lef[p][w] = ++root[p];
		upd(x, p, val, lef[p][w], l, mid);
	} else {
		if(!rig[p][w])
			rig[p][w] = ++root[p];
		upd(x, p, val, rig[p][w], mid + 1, r);
	}
	
}

void rebuild(int prv, int k) {
	For(i, prv, k + 1) 
	if(dp[i]) {
		upd(sum[i] % (mod * 2), (sum[i] % (mod * 2)) & 1, dp[i]);
	}
}

void brut(int p, int x) {
	For(pocz, p, x) { // [pocz + 1; x]
		//if(!(((sum[x] - sum[pocz]) % mod) & 1) && dp[pocz])
		//	cout << "brut " << x << " " << pocz << endl;
		dp[x] += dp[pocz] * !(((sum[x] - sum[pocz]) % mod) & 1);
	}
	dp[x] %= mod;
}

void solve(void) {
	int n;
	scanf("%d", &n);
	For(i, 1, n + 1) {
		scanf("%lld", &c[i]);
		if(i)
			sum[i] = sum[i - 1];
		sum[i] += c[i];
	}
	
	int prv = 1;
	For(i, 1, n + 1) {
		if(i > smieszne)
			dp[i] += get(i, prv);
		if(i % smieszne == 1)
			prv = i;	
		brut(prv, i);
		if(sum[i] % (mod) % 2 == 0)
			++dp[i];
		dp[i] %= mod;
		if(i % smieszne == 0)
			rebuild(prv, i);
	}
	/*For(i, 0, n)
		cout << dp[i + 1] << " ";
	puts("");*/
	printf("%lld\n", dp[n]);
	
}

//0 0 1 0 1 1 2 1 5 7 5 9 15 21 

int32_t main(void){
	int t = 1;
	//scanf("%d", &t);
	while(t--)
		solve();
}