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
#include <cstdio>
#include<algorithm>

using namespace std;

typedef unsigned long long ull;

static const int M = 1000000007;

static int sumy[300001];

static int parz[300001];
static int wskp = 0;
static int nparz[300001];
static int wskn = 0;

static int drzewop[512 * 1024 * 2];
static int drzewon[512 * 1024 * 2];

static void dodaj(int in, int w, bool p){
    int* tab;
    if(p){
        tab = drzewop;
    }
    else{
        tab = drzewon;
    }
    
    in += 512 * 1024;
    while(in){
        tab[in] = (tab[in] + w) % M;
        in /= 2;
    }
}

static int suma(int bp, int ep, int in, int b, int e, bool p){
    int* tab;
    if(p){
        tab = drzewop;
    }
    else{
        tab = drzewon;
    }
    
    if(bp < b){
        bp = b;
    }
    if(ep > e){
        ep = e;
    }
    
    if(bp > ep){
        return 0;
    }
    
    if(bp == b && ep == e){
        return tab[in];
    }
    
    int s = (b + e) / 2;
    
    return (suma(bp, ep, 2 * in, b, s, p) + suma(bp, ep, 2 * in + 1, s + 1, e, p)) % M;
}



static int przygotuj(int* tab, int n){
    sort(tab, tab+n);

    int dup = 0;
    
    for(int i = 1; i < n; ++i){
        if(tab[i] == tab[i-1]){
            ++dup;
        }
        else{
            tab[i-dup] = tab[i];
        }
    }
    
    return n - dup;
}

static int znajdz(int l){
    int *tab, n;
    if(l % 2 == 0){
        tab = parz;
        n = wskp;
    }
    else{
        tab = nparz;
        n = wskn;
    }
    
    return lower_bound(tab, tab + n, l) - tab;
}

static int znajdzp(int l){
    int *tab, n;
    if(l % 2){
        tab = parz;
        n = wskp;
    }
    else{
        tab = nparz;
        n = wskn;
    }
    
    return upper_bound(tab, tab + n, l) - tab;
}

static int rozw[300001];

int main()
{
    int n;
    scanf("%i", &n);
    
    parz[wskp++] = 0;

    for(int i = 1; i <= n; ++i){
        int a;
        scanf("%i", &a);
        sumy[i] = (sumy[i-1] + a) % M;
        
        if(sumy[i] % 2){
            nparz[wskn++] = sumy[i];
        }
        else{
            parz[wskp++] = sumy[i];
        }
    }
    
    wskp = przygotuj(parz, wskp);
    wskn = przygotuj(nparz, wskn);

    for(int i = 0; i <= n; ++i){
        int s = sumy[i];
        int ins = znajdz(s);
      
        int r = suma(0,ins,1,0,512*1024-1,s%2 == 0);
	//printf("%i -> %i %i\n", i, s,znajdzp(s));
	//printf("wskp = %i\n", wskp);
        r = (r + suma(znajdzp(s),512*1024-1,1,0,512*1024-1,s%2)) % M;
        
	if(i == 0){
            r = 1;
        }
        rozw[i] = r;
        dodaj(ins, r, s % 2 == 0);
    }

    printf("%i\n", rozw[n]);

    return 0;
}