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

const long long P=1e9+7;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n;
    cin>>n;
    vector<long long> a(n);
    long long sum=0;
    for(int i=0; i<n; ++i)
    {
        cin>>a[i];
        sum+=a[i];
    }

    if(sum<P)
    {
        vector<long long> dp(n,0);
        if(a[0]%2==0)
            dp[0]=1;
        else
            dp[0]=0;
        long long last=0;
        for(int i=1; i<n; ++i)
            if(a[i]%2==0)
                dp[i]=2*dp[i-1];
            else
            {
                if(dp[i-1]>0)
                {
                    dp[i]=0;
                    last=dp[i-1];
                }
                else
                {
                    if(last==0)
                        dp[i]=1;
                    else
                        dp[i]=2*last;
                }
            }
        cout<<dp[n-1]<<endl;
    }
    else
    {
        vector<long long> pref(n+1,0);
        for(int i=0; i<n; ++i)
            pref[i+1]=(pref[i]+a[i])%P;
        vector<long long> dp(n+1,0);
        dp[0]=1;
        for(int i=1; i<=n; ++i)
            for(int j=0; j<i; ++j)
                if(((pref[i]-pref[j]+P)%P)%2==0)
                    dp[i]=(dp[i]+dp[j])%P;
        cout<<dp[n]<<endl;
    }
    return 0;
}