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
#include <iostream>

using namespace std;

#define P 1000000007
long long prefixSums[300001];
int results[2][300001];

int main() {
  int n, k;
  ios::sync_with_stdio(false);
  cin >> n;
  results[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    cin >> k;
    prefixSums[i] = k + prefixSums[i - 1];
  }
  if (prefixSums[n] >= P) {
    for (int i = 1; i <= n; i++)
      for (int j = 0; j < i; j++)
        if (((prefixSums[i] - prefixSums[j]) % P) % 2 == 0)
          results[0][i] = (results[0][i] + results[0][j]) % P;
  } else {
    results[prefixSums[1] % 2][1] = 1;
    results[1 - (prefixSums[1] % 2)][1] = 0;

    for (int i = 2; i <= n; i++) {
      if ((prefixSums[i] - prefixSums[i - 1]) % 2 == 0) {
        results[0][i] = (2 * results[0][i - 1]) % P;
        results[1][i] = (results[1][i - 1]) % P;
      } else {
        results[0][i] = (results[1][i - 1]) % P;
        results[1][i] = (2 * results[0][i - 1]) % P;
      }
    }
  }
  cout << results[0][n] << endl;
  return 0;
}