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
#include<bits/stdc++.h>
using namespace std;
long long MOD = 1e9 +7;
int main() {

    int n;
    cin >> n;
    vector<long long> vec(n);
    vector<long long> pref(n+1,0);
   // pref[0] = 0;
   bool all_smaller = true;
    for(int k=0;k<n;k++) {
        cin >> vec[k];
        if(vec[k] > 1000)
            all_smaller  = false;
        pref[k+1] = (pref[k] + vec[k])%MOD;
    }
    vector<long long> tab(n,0);
    long long sum = 0;
    long long sum_2 = 0;
    if(all_smaller) {
        for(int k=0;k<n;k++) {

            if(vec[k] % 2 == 0)
                tab[k] = sum_2;
            else {
                tab[k] = (sum - sum_2 + MOD)%MOD;
                sum_2 = (sum - sum_2 + MOD ) %MOD;
            }
            if(pref[k+1] % 2 == 0)
                tab[k]++;
            tab[k]%=MOD;
            sum += tab[k];
            sum%=MOD;
            sum_2 +=tab[k];
            sum_2%=MOD;
            //cout << "k = " << k << " " << tab[k] <<endl;
        }
        cout << tab[n-1];
    }
    else {
        for(int k=0;k<n;k++) {
            for(int j=0;j<k;j++) {
                if(((pref[k+1]-pref[j+1] + MOD ) % MOD ) %2 ==0)
                    tab[k] += tab[j];
                tab[k] %= MOD;
            }
            if(pref[k+1] % 2 == 0)
                tab[k]++;
            tab[k]%=MOD;
            //cout << "k = " << k << " " << tab[k] <<endl;
        }
        cout << tab[n-1];
    }

}