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
#include <cstdio>
#include <map>
#include <vector>
using namespace std;

const int mod = 1e9 + 7;
const int maxN = 3e5 + 10;
int t[maxN];
int N;


int magic(int x) { return x & (-x); }

void add(vector<long long> &tree, int x, int val) {
    int N = tree.size();
    while (x < N) {
        tree[x] = (tree[x] + val) % mod;
        x += magic(x);
    }
}

long long _get(vector<long long> &tree, int x) {
    long long sum = 0;
    while (x) {
        sum += tree[x];
        x -= magic(x);
    }
    return sum % mod;
}


map<int, int> sc;
long long get(vector<long long> &tree, int a, int b) {
    if (b == 0)
        return 0;
    a = sc[a];
    b = sc[b] - 1;
    return (_get(tree, b) - _get(tree, a - 1) + mod) % mod;
}

vector<long long> t0, t1;
int zero;

void prepare_trees() {
    sc[0];
    sc[mod];
    int sum = 0;
    for (int i = 0; i < N; ++i) {
        sum = (mod + sum - t[i]) % mod;
        sc[sum];
    }
    int nr = 0;
    for (auto &it : sc)
        it.second = ++nr;
    t0.resize(nr + 10);
    t1.resize(nr + 10);
}

int get_sum0() {
    if (zero % 2 == 0)
        return (get(t0, zero, mod) + get(t1, 0, zero)) % mod;
    return (get(t1, zero, mod) + get(t0, 0, zero)) % mod;
}

int main() {
    scanf("%d", &N);
    for (int i = 0; i < N; ++i)
        scanf("%d", t + i);
    prepare_trees();
    add(t0, sc[0], 1);
    zero = (mod - t[0]) % mod;
    for (int i = 1; i < N; ++i) {
        int sum_all = get_sum0();
        if (zero % 2 == 0)
            add(t0, sc[zero], sum_all);
        else
            add(t1, sc[zero], sum_all);
        zero = (mod + zero - t[i]) % mod;
    }
    printf("%d\n", get_sum0());
}