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
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#include <bits/stdc++.h>
#define int LL
using namespace std;
#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)
 
#define sim template<class n
sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
sim> auto operator << (ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type 
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
// #ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
// #else
// #define debug(...)
// #endif 
 
#define I(x) #x " =", (x), " "
#define A(a, i) #a "[" #i " =", i, "] =", a[i], " "

using namespace std;

const int MXN = 1e6+5;
LL in[MXN];
int n;

void read()
    {
    ios_base::sync_with_stdio(0);
    cin >> n;
    FOR(i, 1, n)
        cin >> in[i];
    }
LL mod2 = 2e9 + 14;
LL mod = 1e9 + 7;

VPII pom[2];

const int BASE = 1 << 19;
LL t[2][BASE*2];
void insert(int x, int a, LL val)
    {
    a += BASE;
    while(a)
        {
        t[x][a] += val;
        a /= 2;
        }
    }
LL query(int x, int a, int b)
    {
    a += BASE - 1;
    b += BASE + 1;
    LL res = 0;
    while(a / 2 != b / 2)
        {
        if(a % 2 == 0)res += t[x][a+1];
        if(b % 2 == 1)res += t[x][b-1];
        a /= 2;
        b /= 2;
        }
    return res;
    }

VI tree;
PII get_seg(int a, int b)
    {
    int sa = lower_bound(ALL(tree), a) - tree.begin();
    int sb = upper_bound(ALL(tree), b) - tree.begin() - 1;
    return MP(sa, sb);
    }


void add(int x, int a, int val)
    {
    val %= mod2;
    if(val < 0)val += mod2;
    // pom[x].PB(MP(a, val));
    insert(x, get_seg(a, 1).f, val);
    }
int get(int x, int a, int b)
    {
    // LL sum = 0;
    // for(auto i: pom[x])
    //     if(a <= i.f && i.f <= b)
    //         sum += i.s;
    auto pom = get_seg(a, b);
    return query(x, pom.f, pom.s) % mod;
    // return sum % mod;
    }
int get2(int x, int a, int b)
    {
    a %= mod2;
    b %= mod2;
    if(a < 0)a += mod2;
    if(b < 0)b += mod2;
    if(a <= b)return get(x, a, b);
    else return get(x, a, mod2-1) + get(x, 0, b);
    }



LL solve()
    {
    pom[0].clear();
    pom[1].clear();
    LL result = 0;
    LL sum = 0;
    tree.clear();
    REP(i, BASE*2)t[0][i] = t[1][i] = 0;
    
    FOR(i, 0, n)
        {
        tree.PB(sum % mod2);
        sum += in[i];
        }
    tree.PB(-1);
    tree.PB(mod2);
    sum = 0;
    sort(ALL(tree));
    tree.resize(unique(ALL(tree)) - tree.begin());


    add(0, 0, 1);
    FOR(i, 1, n)
        {
        sum += in[i];
        sum %= mod2;
        LL res = 0;

        res = get2(sum % 2, sum - mod+1, sum) +  
              get2(sum % 2 ^ 1, sum - mod2+1, sum - mod);
        res %= mod;
        add(sum % 2, sum, res);

        if(i == n)return res;
        }
    assert(false);
    }

LL dp2[MXN];
LL pref[MXN];
LL solve2()
    {
    LL result = 0;
    LL sum = 0;
    int mods = 0;
    FOR(i, 1, n)dp2[i] = 0;
    FOR(i, 1, n)pref[i] = pref[i-1] + in[i];
    dp2[0] = 1;
    FOR(i, 1, n)
        {
        FOR(j, i, n)
            {
            if((pref[j] - pref[i-1]) % mod % 2 == 0)
                {
                dp2[j] += dp2[i-1];
                dp2[j] %= mod;
                }
            }
        }
    return dp2[n];
    }

int R(int a, int b)
    {
    return rand() % (b-a+1)+a;
    }

#if 0
int32_t main()
    {
    FOR(it, 1, 1e6)
        {
        n = R(1, 10000);
        
        FOR(i, 1, n)
            {
            in[i] = R(0, mod-1);
            }
        cerr << it << endl;
        
        assert(solve() == solve2());
        }
    }
#else
int32_t main()
    {
    read();
    cout << solve() << endl;
    // cout << solve2() << endl;

    

    }
#endif