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
#include <bits/stdc++.h>
using namespace std;

#define MOD 1000000007LL

int n;
long long prefix_sum[300007];
long long column_sum[300007];

int odd_count = 0;
long long values[300007];
vector<long long> odd_positions;
long long powers_of_2[300007];
long long result = 1LL;

void compute_powers() {
    powers_of_2[0] = 1LL;
    for (int i = 1; i <= n; i++) {
        powers_of_2[i] = (powers_of_2[i - 1] * 2LL) % MOD;
    }
}


int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin >> n;

    if (n <= 3000) {
        for (int i = 1; i <= n; i++) {
            cin >> prefix_sum[i];
            prefix_sum[i] += prefix_sum[i - 1];
        }

        for (int col = 1; col <= n; col++) {
            for (int row = 1; row <= col; row++) {
                if (((prefix_sum[col] - prefix_sum[col - row]) % MOD) % 2LL == 0LL) {
                    column_sum[col] += (row < col) ? column_sum[col - row] : 1LL;
                }
            }
            column_sum[col] = column_sum[col] % MOD;
        }

        cout << column_sum[n] % MOD << "\n";
        return 0;
    }
    // else
    for (int i = 1; i <= n; i++) {
        cin >> values[i];
        if (values[i] % 2) {
            odd_count++;
            odd_positions.push_back(i);
        }
    }

    compute_powers();

    if (odd_count == 0) {
        cout << powers_of_2[n - 1] << "\n";
        return 0;
    }

    if (odd_count % 2) {
        cout << "0\n";
        return 0;
    }

    result = (result * (powers_of_2[odd_positions[0] - 1LL])) % MOD;
    result = (result * (powers_of_2[n - odd_positions[odd_positions.size() - 1LL]])) % MOD;

    for (int i = 2; i < odd_positions.size(); i += 2) {
        result = (result * powers_of_2[odd_positions[i] - odd_positions[i - 1]]) % MOD;
    }

    cout << result << "\n";
    return 0;
}