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
#include <iostream>
#include <set>
#include <map>
using namespace std;
const int stala=524288;
const long long mod=1e9+7;
long long tree[2*stala][2];
long long tab[stala];
long long dp[stala];
set<long long>secik;
map<long long,int>mapka;
void update(int index,int ind,long long war)
{
    index+=stala-1;
    tree[index][ind]+=war;
    tree[index][ind]%=mod;
    while(index>1)
    {
        index/=2;
        tree[index][ind]=tree[2*index][ind]+tree[(2*index)+1][ind];
        tree[index][ind]%=mod;
    }
}
long long query(int index,int index2,int ind)
{
    index+=stala-1;
    index2+=stala-1;
    long long war=tree[index][ind];
    if(index!=index2)
    {
        war+=tree[index2][ind];
        war%=mod;
    }
    while(index/2!=index2/2)
    {
        if(index%2==0)
        {
            war+=tree[index+1][ind];
            war%=mod;
        }
        if(index2%2==1)
        {
            war+=tree[index2-1][ind];
            war%=mod;
        }
        index/=2;
        index2/=2;
    }
    return war;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int ile;
    cin>>ile;
    long long suma=0;
    secik.insert(0);
    for(int i=1;i<=ile;i++)
    {
        cin>>tab[i];
        suma+=tab[i];
        secik.insert(suma%mod);
    }
    int index=0;
    while(!secik.empty())
    {
        index++;
        long long zmienna=*(secik.begin());
        mapka[zmienna]=index;
        secik.erase(secik.begin());
    }
    update(mapka[0],0,1);
    suma=0;
    for(int i=1;i<=ile;i++)
    {
        suma+=tab[i];
        suma%=mod;
        dp[i]=query(1,mapka[suma],suma%2);
        if(mapka[suma]<index)
        {
            dp[i]+=query(mapka[suma]+1,index,(suma+1)%2);
            dp[i]%=mod;
        }
        update(mapka[suma],suma%2,dp[i]);
    }
    cout<<dp[ile];

    return 0;
}