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 <iostream>
#include <set>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;
//#undef _HOME_
#ifdef _HOME_
    #define DEBUG(x) x
#else
    #define DEBUG(x)
#endif
#define REP(x,n) for(int x=0;x<(n);++x)
#define FOREACH(x,n) for(__typeof(n.begin()) x = (n).begin(); x != (n).end(); ++x)
#define RESULT(x) {cout<<(x);return 0;}

typedef long long LL;

const int MAX_N = 300001;
const LL BASE = 1000000007LL;
LL tab[MAX_N];
LL sumLeft[MAX_N];
int n;

const LL cut(LL x) {
	return x%BASE;
}

// all groups are below BASE - can be divided in all even groups
LL heura1() {
	if (sumLeft[n-1]&1)
		return 0;
	LL result = 1;
	int groups = 0;
	REP(x,n)
		if (!(sumLeft[x]&1)) {
			++groups;
			DEBUG(cerr<<"cut at "<<x<<endl;)
		}
	REP(x,groups-1)
		result = cut(result<<1);
	return result;
}

// max 3000 items
const int MID_N = 3001;

LL solveHeur(int start) {
	LL result = 0;
	LL startVal = start ? sumLeft[start-1] : 0;
	for(int x=start;x<n-1;++x)
		if (!(cut(sumLeft[x]-startVal)&1))
			result += solveHeur(x+1);
	if (!(cut(sumLeft[n-1]-startVal)&1))
		return result+1;
	return result;
}

LL heura2() {
	return solveHeur(0);
}

int main() {
	ios_base::sync_with_stdio(0);
	cin>>n;
	LL sum = 0;
	REP(x,n) {
		cin>>tab[x];
		sum = sum+tab[x];
		sumLeft[x] = sum;
	}
	if (sum < BASE)
		RESULT(heura1())
	else if(n <= 3000)
		RESULT(heura2())
	else
		RESULT("NOPE")
}