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

typedef long long int LL;

const int MAX_N = 300005;
const int MAX_SMALL_N = 7005;
const LL P = 1000000007;

int n;
LL nums[MAX_N], sums[MAX_N], res[MAX_N];
LL dp[MAX_SMALL_N][MAX_SMALL_N];

LL solveSlow()
{
    for(int i = 0; i < n; ++i)
    {
        if((sums[i]%P)%2 == 0)
        {
            dp[i][0] = 1;
            res[i] = 1;
        }

        for(int j = 0; j < i; ++j)
        {
            const LL actModSum = ((sums[i] - sums[j]) % P % 2);

            if(actModSum != 0)
            {
                continue;
            }

            dp[i][j] = res[j];
            res[i] = (res[i] + res[j]) % P;
        }

        /*
        cout << "i: " << i << ", res[i]: " << res[i] << endl;
        for(int j = 0; j < i; ++j)
        {
            cout << "j: " << j << ", dp[i][j]: " << dp[i][j] << endl;
        }
        cout << "--------" << endl;
        */
    }

    return res[n-1];
}

LL allEvenCount[MAX_N], lastOddCount[MAX_N];

LL solveLessThanP()
{
    if(nums[0] % 2 == 0)
    {
        allEvenCount[0] = 1;
    }
    else
    {
        lastOddCount[0] = 1;
    }

    for(int i = 1; i < n; ++i)
    {
        if(nums[i] % 2 == 0)
        {
            allEvenCount[i] = (2*allEvenCount[i-1]) % P;
            lastOddCount[i] = lastOddCount[i-1];
        }
        else
        {
            allEvenCount[i] = lastOddCount[i-1];
            lastOddCount[i] = (2*allEvenCount[i-1]) % P;
        }
    }

    return allEvenCount[n-1];
}

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> n;
    for(int i = 0; i < n; ++i)
    {
        cin >> nums[i];

        sums[i] = nums[i] + (i > 0 ? sums[i-1] : 0);
    }

    const LL result = sums[n-1] < P
        ? solveLessThanP()
        : solveSlow();

    cout << result << endl;

    return 0;
}