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
#include "bits/stdc++.h" // Ignacy Boehlke
using namespace std;     // XIII LO Szczecin
template<class A, class B> ostream& operator << (ostream& os, const pair<A, B>& p) {return os << '{' << p.first << ", " << p.second << '}';}
template<class T> auto operator << (ostream& os, const T& v) -> decltype(v.begin(), os) {os << '{';for (auto i : v) os << i << ", ";return os << '}';}
#ifdef DEBUG
#define D(x...) x
#else
#define D(x...)
#endif
#define LN(x) D(cerr << #x << ": " << x << ' ')
#define LOG(x) D(cerr << #x << ": " << x << '\n')
#define ssize(x) ((int)x.size())
#define FOR(a, b, c) for(int a = (b); a <= (c); ++a)
#define REP(a, b) FOR(a, 0, b - 1)
#define ALL(x) (x).begin(), (x).end()
#define fi first
#define se second
using ll = long long;
using pii = pair<int, int>;

constexpr int MOD = 1000000007;

int add(int a, int b) {return (a + b >= MOD ? a + b - MOD : a + b);}

struct SegmentTree {
    int n;
    vector<array<int, 2>> t;
    SegmentTree(int _n) : n(_n), t(4 * n) {}
    int _get(int v, int tl, int tr, int l, int r, bool m) {
        if (l > r) return 0;
        if (tl == l && tr == r) return t[v][m];
        int tm = (tl + tr) / 2;
        return add(_get(v * 2, tl, tm, l, min(r, tm), m),
                   _get(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, m));
    }
    int get(int i, int m) {LN(i); LOG(m); return add(_get(1, 0, n - 1, 0, i - 1, m), _get(1, 0, n - 1, i, n - 1, !m));}
    void _set(int v, int tl, int tr, int tar, int val, bool m) {
        if (tl == tr) t[v][m] = val;
        else {
            int tm = (tl + tr) / 2;
            if (tar <= tm) _set(v * 2, tl, tm, tar, val, m);
            else _set(v * 2 + 1, tm + 1, tr, tar, val, m);
            t[v][m] = add(t[v * 2][m], t[v * 2 + 1][m]);
        }
    }
    void set(int i, int val, bool m) {LN(i); LN(val); LOG(m); _set(1, 0, n - 1, i, val, m);}
};

int main() {
    int n;
    scanf("%d", &n);
    vector<int> in(n + 1), pos(n + 1), dp(n + 1);
    vector<pii> p(n + 1);
    FOR(i, 1, n) {
        scanf("%d", &in[i]);
        p[i] = {add(p[i - 1].fi, in[i]), i};
    }
    sort(ALL(p));
    REP(i, n + 1) pos[p[i].se] = i;

    SegmentTree t(n + 1);
    dp[0] = 1;
    t.set(0, 1, 0);
    FOR(i, 1, n) {
        int poss = (int)(lower_bound(ALL(p), make_pair(p[pos[i]].fi + 1, 0)) - p.begin());
        LOG(poss);
        dp[i] = t.get(poss, p[pos[i]].fi & 1);
        t.set(pos[i], dp[i], p[pos[i]].fi & 1);
    }
    printf("%d\n", dp[n]);
}