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

const int N = 300000;

const int MOD = 1000 * 1000 * 1000 + 7;

int n;
int values[N];
int totals[N+1];
int64_t sums[N+1];

void quickSolve(){
    int odd = values[0] % 2;
    int even = 1 - odd;

    for(int i = 1; i < n; i++) {
        if(values[i] % 2 == 0){
            even = (2*even) % MOD;
        } else {
            int tmp = even;
            even = odd;
            odd = (2*tmp) % MOD;
        }
    }

    std::cout << even << "\n";
}

int getSum(int beg, int end){
    return (sums[end] - sums[beg]) % MOD;
}

int main(){
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);

    std::cin >> n;

    int64_t sum = 0;

    for(int i = 0; i < n; i++){
        sums[i] = sum;
        std::cin >> values[i];
        sum += values[i];
    }
    sums[n] = sum;

    if(sum < MOD){
        quickSolve();
        return 0;
    }

    totals[0] = 1;

    for(int i = 0; i < n; i++){
        int64_t sum = 0;
        for(int j = i; j < n; j++){
            if(getSum(i, j+1) % 2 == 0){
                totals[j+1] = (totals[j+1] + totals[i]) % MOD;
            }
        }
    }

    std::cout << totals[n] << "\n";

    return 0;
}