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
215
216
217
218
#include <vector>
#include <iostream>
using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int,int>;
using graph = vector<vi>;

#define FOR(name__, upper__) for (int name__ = 0; name__ < (upper__); ++name__)
#define all(x) begin(x), end(x)
#define mp make_pair
#define mt make_tuple

template<class T>
void initialize_matrix(vector<vector<T>>& matrix, int rows, int cols, T value) {
	assert(matrix.empty());
	FOR (row, rows) 
		matrix.emplace_back(cols, value);
}

const ll mod = 1e9 + 7;

struct item {
    ll min_d, max_d;
    ll dp_odd, dp_even;
    ll delta, swaps;
};

struct segment_tree {
    #define LEFT(i) 2 * i
    #define RIGHT(i) 2 * i + 1

    int N;
    vector<item> values;
    vi lo, hi;

    // const item NEUTRAL_ELEMENT = { +mod, -mod, 0, 0, 0, 0};

    void init(int a, int b, int i = 1) {
lo[i] = a; hi[i] = b; 

        if ( a == b ) return;

        int m = (a+b)/2;
        init(a, m, LEFT(i));
        init(m + 1, b, RIGHT(i));
    }
    

    segment_tree(int n) : N(4*n + 1), lo(N, -1), hi(N, -1), values(N) {
        FOR (i, N) {
            values[i].min_d = mod * mod;
            values[i].max_d = - mod * mod;
            values[i].dp_odd = values[i].dp_even = values[i].delta = values[i].swaps = 0;
        }
        init(0, n - 1);
    }

    item merge(item a, item b) {
        return { std::min(a.min_d, b.min_d), std::max(a.max_d, b.max_d), a.dp_odd + b.dp_odd, a.dp_even + b.dp_even, 0 };
    }

    item single(ll dp, ll dist) {
        return { dist, dist, dp, dp, 0, 0};
    }

    void propagate(int i) {
        values[LEFT(i)].delta += values[i].delta;
        values[LEFT(i)].swaps += values[i].swaps;
        values[RIGHT(i)].delta += values[i].delta;
        values[RIGHT(i)].swaps += values[i].swaps;
        values[i].delta = 0;
        values[i].swaps = 0;
    }

    void update(int i) {
        values[i].max_d = std::max(values[LEFT(i)].max_d + values[LEFT(i)].delta, values[RIGHT(i)].max_d + values[RIGHT(i)].delta);
        values[i].min_d = std::min(values[LEFT(i)].min_d + values[LEFT(i)].delta, values[RIGHT(i)].min_d + values[RIGHT(i)].delta);
        ll left_dp_even = values[LEFT(i)].dp_even;
        ll left_dp_odd = values[LEFT(i)].dp_odd;
        if (values[LEFT(i)].swaps & 1) swap(left_dp_even, left_dp_odd);

        ll right_dp_even = values[RIGHT(i)].dp_even;
        ll right_dp_odd = values[RIGHT(i)].dp_odd;
        if (values[RIGHT(i)].swaps & 1) swap(right_dp_even, right_dp_odd);
        
        values[i].dp_even = left_dp_even + right_dp_even;
        values[i].dp_odd = left_dp_odd + right_dp_odd;
    }
    
    // 0 - normal - 1 inverted - 2 mix
    int state(int i, ll add = 0) {
        if ((values[i].min_d/mod == (values[i].min_d + values[i].delta + add)/mod) && 
            (values[i].max_d/mod == (values[i].max_d + values[i].delta + add)/mod)) return 0;
        else if (
            (values[i].min_d/mod == (values[i].min_d + values[i].delta + add)/mod) && 
            (values[i].max_d/mod == (values[i].max_d + values[i].delta + add)/mod)) return 1;
        else return 2;
    }

    void update_range(int a, int b, ll dist, int i = 1) {
        if ( b < lo[i] || hi[i] < a ) return; 
        else if ( a <= lo[i] && hi[i] <= b && (state(i, dist) < 2)) {
            values[i].delta += dist;
            if (state(i) == 0) values[i].swaps += dist % 2;
            else if (state(i) == 1) values[i].swaps += 1 - dist % 2;
            return;
        }

        propagate(i);
        update_range(a, b, dist, LEFT(i));
        update_range(a, b, dist, RIGHT(i));
        update(i);
    }

    void update_dp_element(int a, int b, ll dp, int i = 1) {
        if ( b < lo[i] || hi[i] < a ) return; 
        else if ( a <= lo[i] && hi[i] <= b) {
            values[i].min_d = values[i].max_d = 0;
            values[i].dp_odd = values[i].dp_even = dp;
            values[i].delta = values[i].swaps = 0;
            return;
        }

        propagate(i);
        update_dp_element(a, b, dp, LEFT(i));
        update_dp_element(a, b, dp, RIGHT(i));
        update(i);
    }
    
    void update_dp(int index, ll dp) {
        update_dp_element(index, index, dp);
    }

    ll calc(int a, int b, int i = 1) {
        if ( b < lo[i] || hi[i] < a ) return 0; 
        else if ( a <= lo[i] && hi[i] <= b && state(i) < 2) {
            cout << "RETURING" << endl;
            cout << values[i].dp_even << endl;
            cout << values[i].dp_odd << endl;

            if (values[i].swaps & 1) return values[i].dp_odd;
            else return values[i].dp_even;
        }

        propagate(i);
        ll left = calc(a, b, LEFT(i));
        ll right = calc(a, b,RIGHT(i));
        update(i);
        return (left + right) % mod;
    }
    
    ll query(int index) {
        return calc(1, index);
    }

    #undef LEFT
    #undef RIGHT
};

ll solve_opt(int n, vi& A) {
    segment_tree segtree(n + 1);
    vll p(n + 1, 0);
    FOR (i, n) p[i + 1] = p[i] + A[i];

    vll dp(n + 1, 0);
    dp[0] = 1;
    
    cout << segtree.calc(0, 0) << endl;
    
    segtree.update_dp(0, 1);
    for (int i = 1; i <= n; i++) {
        segtree.update_range(0, i - 1, A[i - 1]);
        dp[i] = segtree.calc(0, i - 1);
        cout << dp[i] << endl;
        segtree.update_dp(i, dp[i]);
    }
    return dp[n];
}

ll solve_brute(int n, vi& A) {
    vll p(n + 1, 0);
    FOR (i, n) p[i + 1] = p[i] + A[i];

    vll dp(n + 1, 0);
    dp[0] = 1;
    
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < i; j++) {
            ll pref_sum = p[i] - p[j];
            
            if (((pref_sum % mod) & 1) == 0) {
                dp[i] += dp[j];
                dp[i] %= mod;
            }
        }
    }
    return dp[n];
}

void go() {
    int n; cin >> n;
    vi A(n); for (auto &i : A) cin >> i;
    
    ll sol = solve_brute(n, A);
    cout<<sol << endl;
}

int main() {
	ios::sync_with_stdio(false); 
	cin.tie(0);

	go();

	return 0;
}