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
#include <bits/stdc++.h>
#define dbg(x) " [" << #x << ": " << (x) << "] "
using namespace std;
template<typename A,typename B>
ostream& operator<<(ostream& out,const pair<A,B>& p) {
    return out << "(" << p.first << ", " << p.second << ")";
}
template<typename T>
ostream& operator<<(ostream& out,const vector<T>& c) {
    out << "{";
    for(auto it = c.begin(); it != c.end(); it++) {
        if(it != c.begin()) out << ", ";
        out << *it;
    }
    return out << "}";
}
const int mod = 1e9 + 7;
int par(long long n) {
    return (n / mod + n) & 1;
}
vector<vector<long long>> t(2);
void upd(int v,int tl,int tr,int id,long long x,int i) {
    if(tl + 1 == tr) {
        t[i][v] += x;
        t[i][v] %= mod;
        return;
    }
    int tm = (tl + tr) >> 1;
    if(id < tm) {
        upd(2*v,tl,tm,id,x,i);
    } else {
        upd(2*v+1,tm,tr,id,x,i);
    }
    t[i][v] = t[i][2*v] + t[i][2*v+1];
}
long long get(int v,int tl,int tr,int l,int r,int i) {
    if(l >= r) return 0;
    if(tl == l && tr == r) {
        return t[i][v];
    }
    int tm = (tl + tr) >> 1;
    return (get(2*v,tl,tm,l,min(r,tm),i) + get(2*v+1,tm,tr,max(tm,l),r,i)) % mod;
}
void solve() {
    int n;
    cin >> n;
    vector<long long> v(n + 1),s(n + 1);
    map<int,int> mp;
    for(int i = 1; i < n + 1; i++) {
        cin >> v[i];
        s[i] = s[i - 1] + v[i];
        mp[s[i] % mod]++;
    }
    int c = 0;
    vector<int> vv;
    unordered_map<int,int> mpp;
    mp[0] = 1;
    for(auto [a,b] : mp) {
        vv.push_back(a);
        mpp[a] = c;
        c++;
    }
    t[0].resize(4 * c);
    t[1].resize(4 * c);
    upd(1,0,c,0,1,0);
    for(int i = 1; i <= n; i++) {
        int id = mpp[s[i] % mod];
        long long sm = get(1,0,c,0,id+1,par(s[i]));
        sm += get(1,0,c,id+1,c,par(s[i]) ^ 1);
        sm %= mod;
        upd(1,0,c,id,sm,par(s[i]));
        if(i == n) {
            cout << sm << endl;
        }
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int testNum = 1;
    //cin >> testNum;
    for(int i = 1; i <= testNum; i++) {
        solve();
    }
    return 0;
}