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
/*
    Piotr Bieńkowski
    bbienkos@gmail.com
    Akademickie Liceum Ogólnokształcące Politechniki Wrocławskiej
*/

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define pii pair<int, int>
#define debug(x); cerr << #x << " = " << x << "\n";
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

#define int long long

const int N = 3e5 + 7;
const int MOD = 1e9 + 7;

int n;
int tab[N];
int pref[N];

int odejmowanie(int x, int y)
{
    y %= MOD;
    int temp = x - y;
    if (temp < 0)
    {
        return MOD + temp;
    }
    return temp;
}

int sum_pref(int l, int r)
{
    int ret = 0;
    for(int i = l; i <= r; i++)
    {
        ret = (ret + tab[i]) % MOD;
    }
    return ret;
    if(l == 0)
        return pref[r];
    return (odejmowanie(pref[r], pref[l - 1])) % MOD;
}

unordered_map<int, int> S;

int ans = 0;
int solve(int l)
{
    if(S[l] != 0)
    {
        ans = (ans + S[l] - 1) % MOD;
        return S[l] - 1;
    }
    if(l >= n)
    {
        if (l == n) 
        {
            ans = (ans + 1) % MOD;
            return 1;
        }
        return 0;
    }
    int ret = 0;
    for(int i = 0; l + i - 1 < n; i++)
    {
        if((sum_pref(l, l + i) % MOD) % 2 == 0)
        {
            ret = (ret + solve(l + i + 1)) % MOD;
        }
    }
    S[l] = (ret + 1) % MOD;
    return ret;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> tab[i];
    pref[0] = tab[0];
    for(int i = 1; i < n; i++)
        pref[i] = (tab[i] + pref[i - 1]) % MOD;
    solve(0);
    cout << ans % MOD << "\n";
}