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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#ifdef LOCAL
#define debug(...) __VA_ARGS__
#else
#define debug(...) {}
#endif
const ll mod = 1e9+7;
const int base = (1<<19);
ll tree[2*base][2];
pair<ll,int> pref[300001];
ll tab[300001];
pair<int,bool> where[300001];
void change(int v, ll x, bool y){
    v += base;
    tree[v][y] = (tree[v][y]+x)%mod;
    v /= 2;
    while (v){
        tree[v][0] = (tree[2*v][0]+tree[2*v+1][0])%mod;
        tree[v][1] = (tree[2*v][1]+tree[2*v+1][1])%mod;
        v /= 2;
    }
}
int query(int a, int b, bool y){
    a += base-1;
    b += base+1;
    ll suma = 0;
    while (b-a > 1){
        if (!(a%2)) suma = (suma+tree[a+1][y])%mod;
        if (b%2) suma = (suma+tree[b-1][y])%mod;
        a /= 2;
        b /= 2;
    }
    return suma;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int i;
    int n;
    cin>>n;
    change(0,1,0);
    pref[0] = {0,0};
    for (i = 1; i < n+1; i++){
        cin>>tab[i];
        pref[i].first = (pref[i-1].first+tab[i])%mod;
        pref[i].second = i;
    }
    stable_sort(pref,pref+n+1);
    int pointer = 0;
    for (i = 0; i < n+1; i++){
        if (i && pref[i].first != pref[i-1].first) pointer++;
        where[pref[i].second] = {pointer,pref[i].first%2};
        //cout<<pref[i].second<<" # "<<pref[i].first<<" # "<<where[pref[i].second].first<<" "<<where[pref[i].second].second<<"\n";
    }
    ll aktwy = 0;
    for (i = 1; i < n+1; i++){
        aktwy = query(0,where[i].first,where[i].second)%mod;
        aktwy = (aktwy+query(where[i].first+1,n+1,where[i].second^1))%mod;
        change(where[i].first,aktwy,where[i].second);
    } 
    cout<<aktwy<<"\n";
    return 0;
}