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
//  Created by Michal Kowalski on 08/12/2021.
//

#include <iostream>
#include <vector>

int N;
int T[300005];
long long A = 1000000007;
long long S = 0;

bool partition_is_correct(std::vector<std::vector<int>> & pp) {
    for (int j=0;j<pp.size();++j) {
        std::vector<int> indexes = pp[j];
        long long sum = 0;
        for (int k=0;k<indexes.size();++k) {
            sum = (sum + (long long)T[indexes[k]]) % A;
        }

        if (sum % 2 == 1) return false;
    }
    return true;
}

std::vector<std::vector<int>> create_partition(std::vector<int> & v) {
    int s = v.size();
    int si = 0;
    std::vector<std::vector<int>> p;
    for (int i = 0; i < s; ++i) {
        std::vector<int> range;
        for (int a = si; a<v[i]; ++a) range.push_back(a);
        si = v[i];
        p.push_back(range);
    }
    std::vector<int> range;
    for (int a = si; a<N; ++a) range.push_back(a);
    p.push_back(range);
    return p;
}

void check_solution(std::vector<int> & v) {
    std::vector<std::vector<int>> P = create_partition(v);
    S += partition_is_correct(P) ? 1 : 0;
//    for (int i=0;i<v.size();++i) printf("%d ",v[i]);
//    printf("\n");
}

bool next_comb(std::vector<int> & v, int N) {
    int i = v.size() - 1;
    if (v[i] + 1 < N) {
        ++v[i];
        return true;
    }
    return false;
}

bool move_prev_part(std::vector<int> & v, int N) {
    int i = v.size() - 1;
    while(true) {
        --i;
        if (i < 0) return false;
        if (v[i] + 1 < v[i+1]) {
            ++v[i];
            break;
        }
    }
    // reset partitions after i
    for (int j = i + 1; j < v.size(); ++j) v[j] = v[j-1] + 1;
    return true;
}

void part(int N, int P) {
    std::vector<int> indexes;
    for (int i=0;i<P;++i) indexes.push_back(i+1);

    while(true) {
        check_solution(indexes);
        if (next_comb(indexes, N)) {
            continue;
        } else {
            if (move_prev_part(indexes, N)) continue;
            else break;
        }
    }
}

std::vector<std::vector<int>> partitions_0(int n) {
    std::vector<std::vector<int>> v;
    std::vector<int> a;
    for (int i=0;i<n;++i) a.push_back(i);
    v.push_back(a);
    return v;
}

long long mod_power(int n) {
    long long m = 1;
    for (int i=1;i<=n;++i) {
        m = (m * (long long)2) % A;
    }
    return m;
}

int main(int argc, const char * argv[]) {
    scanf("%d",&N);
    for (int i=0;i<N; ++i) scanf("%d",&T[i]);
    if (N<16) {
        std::vector<std::vector<int>> p0 = partitions_0(N);
        S += (int)partition_is_correct(p0);
        for (int i=1; i<N; ++i) {
            part(N, i);
        }
    } else {
        std::vector<int> vT;
        int open = -1;
        int even_count = 0;
        for (int i=0;i<N; ++i) {
            if(T[i] % 2 == 1) {
                if (open == -1) open = i;
                else {
                    open = -1;
                    ++even_count;
                }
            } else {
                ++even_count;
            }
        }
        if (open != -1) S = 0;
        else {
            S = mod_power(even_count-1);
        }
    }
    printf("%lld\n",S);
    return 0;
}