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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
/*
 * =====================================================================================
 *
 *  Author: Jakub Nowak (MrQubo)
 *
 * =====================================================================================
 */

// region standard
#pragma GCC optimize "-Ofast"

#ifndef DEBUG
#	define NDEBUG
#endif  // DEBUG

#include <bits/stdc++.h>
using namespace std;

#pragma GCC diagnostic ignored "-Wunused-macros"

namespace std {
	// type_traits logical operations mock for C++11
#if __cplusplus < 201700L
	template <bool B>
	using bool_constant = integral_constant<bool, B>;
	template <typename...> struct conjunction : true_type { };
	template <typename B1> struct conjunction<B1> : B1 { };
	template <typename B1, typename... Bn>
	struct conjunction<B1, Bn...>
		: conditional<bool(B1::value), conjunction<Bn...>, B1>::type { };
	template <class...> struct disjunction : false_type { };
	template <class B1> struct disjunction<B1> : B1 { };
	template <class B1, class... Bn>
	struct disjunction<B1, Bn...>
		: conditional<bool(B1::value), B1, disjunction<Bn...>>::type  { };
	template <typename B>
	struct negation : bool_constant<!bool(B::value)> { };
#endif
}

#define guard(x) if (!(x))

#define _CAT(A, B) A ## B
#define CAT(A, B) _CAT(A, B)
#define _CAT3(A, B, C) A ## B ## C
#define CAT3(A, B, C) _CAT3(A, B, C)
#define _STR(...) #__VA_ARGS__
#define STR(...) _STR(__VA_ARGS__)
#define _FIRST(F, ...) F
#define FIRST(...) _FIRST(__VA_ARGS__, )
#define SKIP1(F, ...)  __VA_ARGS__
#define SKIP2(F, ...)  SKIP1(__VA_ARGS__, )
#define SKIP3(F, ...)  SKIP2(__VA_ARGS__, )
#define SKIP4(F, ...)  SKIP3(__VA_ARGS__, )
#define SKIP5(F, ...)  SKIP4(__VA_ARGS__, )
#define SKIP6(F, ...)  SKIP5(__VA_ARGS__, )
#define SKIP7(F, ...)  SKIP6(__VA_ARGS__, )
#define SKIP8(F, ...)  SKIP7(__VA_ARGS__, )
#define SKIP9(F, ...)  SKIP8(__VA_ARGS__, )
#define SKIP10(F, ...) SKIP9(__VA_ARGS__, )
#define SKIP11(F, ...) SKIP10(__VA_ARGS__, )
#define SKIP12(F, ...) SKIP11(__VA_ARGS__, )
#define SKIP(N, ...) CAT(SKIP, N)(__VA_ARGS__, )
#define COUNT(...) FIRST(SKIP12(__VA_ARGS__, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1))
#ifdef DEBUG
	#define MAGIC do { clog << boolalpha; } while(0)
	#define PRINT(msg) do { clog << "DBG:" << __LINE__ << ">	" << msg << endl; } while(0)
#else
	#define MAGIC do { ios_base::sync_with_stdio(false); cin.tie(nullptr); } while(0)
	#define PRINT(msg) do { } while(0)
	#define clog DONT_USE_CLOG!!!!!!!
	#define cerr DONT_USE_CERR!!!!!!!
	#define endl DONT_USE_ENDL!!!!!!!
#endif  // DEBUG
#define _DBG1(x, ...)  STR(x) << ": " << flush << (x) << flush
#define _DBG2(x, ...)  STR(x) << ": " << flush << (x) << flush << " \t" << _DBG1(__VA_ARGS__)
#define _DBG3(x, ...)  STR(x) << ": " << flush << (x) << flush << " \t" << _DBG2(__VA_ARGS__)
#define _DBG4(x, ...)  STR(x) << ": " << flush << (x) << flush << " \t" << _DBG3(__VA_ARGS__)
#define _DBG5(x, ...)  STR(x) << ": " << flush << (x) << flush << " \t" << _DBG4(__VA_ARGS__)
#define _DBG6(x, ...)  STR(x) << ": " << flush << (x) << flush << " \t" << _DBG5(__VA_ARGS__)
#define _DBG7(x, ...)  STR(x) << ": " << flush << (x) << flush << " \t" << _DBG6(__VA_ARGS__)
#define _DBG8(x, ...)  STR(x) << ": " << flush << (x) << flush << " \t" << _DBG7(__VA_ARGS__)
#define _DBG9(x, ...)  STR(x) << ": " << flush << (x) << flush << " \t" << _DBG8(__VA_ARGS__)
#define _DBG10(x, ...) STR(x) << ": " << flush << (x) << flush << " \t" << _DBG9(__VA_ARGS__)
#define _DBG11(x, ...) STR(x) << ": " << flush << (x) << flush << " \t" << _DBG10(__VA_ARGS__)
#define _DBG12(x, ...) STR(x) << ": " << flush << (x) << flush << " \t" << _DBG11(__VA_ARGS__)
#define _DBG(...) CAT(_DBG, COUNT(__VA_ARGS__))(__VA_ARGS__, )
#define DBG(...) PRINT(_DBG(__VA_ARGS__))
#define PDBG(msg, ...) PRINT(msg << flush << _DBG(__VA_ARGS__))

#define ST first
#define ND second
#define EM emplace
#define EB emplace_back
#define IN insert
#define PB push_back
#define vec vector
#define arr array
#define uset unordered_set
#define umap unordered_map
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using str = string;
using PI = pair<int, int>;
using PLL = pair<ll, ll>;
using VI = vec<int>;
using VVI = vec<VI>;
using VLL = vec<ll>;

#define ALL(x) begin((x)), end((x))


template <typename T>
inline T posmod(T x, T m)
{
  return (x % m + m) % m;
}

template <typename T>
inline T mini(T & a, T const & b)
{
	return a = min(a, b);
}
template <typename T>
inline T maxi(T & a, T const & b)
{
	return a = max(a, b);
}

template <typename T>
inline T fpow(T a, ull b, T M)
{
	T r(1);
	while (b > 0) {
		if (b & 1)	{
			r *= a;
			r %= M;
		}

		a *= a;
		a %= M;
		b >>= 1;
	}
	return r;
}


// ostream out ostream
template <typename Iter>
void ooo(Iter first, Iter last, char const * delim, ostream & os)
{
	while (first != last) {
		os << *(first++) << delim;
	}
}

// ostream out
template <typename Iter>
inline void oo(Iter first, Iter last, char const * delim)
{
	ooo(first, last, delim, cout);
}

// container ostream out
template <typename C>
inline void coo(C V, char const * delim)
{
	ooo(ALL(V), delim, cout);
}

// infix out ostream
template <typename Iter>
void ioo(Iter first, Iter last, char const * delim, ostream & os)
{
	if (first == last)
		return;
	os << *(first++);
	while (first != last) {
		os << delim << *(first++);
	}
}

// infix out
template <typename Iter>
inline void io(Iter first, Iter last, char const * delim)
{
	ioo(first, last, delim, cout);
}

// container infix out
template <typename C>
inline void cio(C V, char const * delim)
{
	ioo(ALL(V), delim, cout);
}

#ifdef DEBUG
template <typename T, typename S>
ostream & operator << (ostream & os, pair<T, S> const & p)
{
	return os << "(" << p.ST << ", " << p.ND << ")";
}
template <typename... Args>
ostream & operator << (ostream & os, map<Args...> const & S)
{
	os << "{";
	ioo(ALL(S), ", ", os);
	return os << "}";
}
template <typename... Args>
ostream & operator << (ostream & os, umap<Args...> const & S)
{
	os << "{";
	ioo(ALL(S), ", ", os);
	return os << "}";
}
template <typename... Args>
ostream & operator << (ostream & os, multimap<Args...> const & S)
{
	os << "{";
	ioo(ALL(S), ", ", os);
	return os << "}";
}
template <typename... Args>
ostream & operator << (ostream & os, unordered_multimap<Args...> const & S)
{
	os << "{";
	ioo(ALL(S), ", ", os);
	return os << "}";
}
template <typename... Args>
ostream & operator << (ostream & os, set<Args...> const & S)
{
	os << "{";
	ioo(ALL(S), ", ", os);
	return os << "}";
}
template <typename... Args>
ostream & operator << (ostream & os, uset<Args...> const & S)
{
	os << "{";
	ioo(ALL(S), ", ", os);
	return os << "}";
}
template <typename... Args>
ostream & operator << (ostream & os, multiset<Args...> const & S)
{
	os << "{";
	ioo(ALL(S), ", ", os);
	return os << "}";
}
template <typename... Args>
ostream & operator << (ostream & os, unordered_multiset<Args...> const & S)
{
	os << "{";
	ioo(ALL(S), ", ", os);
	return os << "}";
}
template <typename... Args>
ostream & operator << (ostream & os, vec<Args...> const & V)
{
	os << "[";
	ioo(ALL(V), ", ", os);
	return os << "]";
}
template <typename T, size_t N>
ostream & operator << (ostream & os, arr<T, N> const & A)
{
	os << "[";
	ioo(ALL(A), ", ", os);
	return os << "]";
}
template <typename... Args>
ostream & operator << (ostream & os, valarray<Args...> const & VA)
{
	os << "[";
	ioo(ALL(VA), ", ", os);
	return os << "]";
}
#endif  // DEBUG

// istream in istream
template <typename Iter>
void iii(Iter to, ll n, istream & is)
{
	while(n--) {
		is >> *(to++);
	}
}

// istream in
template <typename Iter>
void ii(Iter to, ll const & n)
{
	iii(to, n, cin);
}

// container istream in
template <typename C>
void cii(C & V, ll const & n)
{
	iii(begin(V), n, cin);
}

// container istream in
template <typename C>
C cii(ll const & n)
{
	C V(n);
	iii(begin(V), n, cin);
	return V;
}
// endregion


constexpr ll MOD = 1'000'000'007;


struct Tree
{
	constexpr static int LOG = 30;
	constexpr static int BASE = 1 << LOG;

	struct Node
	{
		Node * l = nullptr;
		Node * r = nullptr;
		ll sum[2] {0, 0};

		Node * left()
		{
			if (l == nullptr)
				l = new Node();
			return l;
		}

		Node * right()
		{
			if (r == nullptr)
				r = new Node();
			return r;
		}
	};

	Node root;

	void update(Node * v)
	{
		for (int c = 0; c < 2; c += 1)
			v->sum[c] = (v->left()->sum[c] + v->right()->sum[c]) % MOD;
	}

	ll get_sum(int a, int b, int c)
	{
		return get_sum(a, b, c, 0, BASE, &root);
	}
	ll get_sum(int a, int b, int c, int s, int e, Node * v)
	{
		if (b <= s or e <= a)
			return 0;
		if (a <= s and e <= b)
			return v->sum[c];

		int m = (s+e) / 2;
		ll x = 0;
		x += get_sum(a, b, c, s, m, v->left());
		x += get_sum(a, b, c, m, e, v->right());
		x %= MOD;
		return x;
	}

	void add(int a, ll c)
	{
		add(a, a+1, c, 0, BASE, &root);
	}
	void add(int a, int b, ll c, int s, int e, Node * v)
	{
		if (b <= s or e <= a)
			return;
		if (a <= s and e <= b) {
			v->sum[a%2] += c;
			return;
		}

		int m = (s+e) / 2;
		add(a, b, c, s, m, v->left());
		add(a, b, c, m, e, v->right());
		update(v);
	}
};


struct Solve
{
	int N;
	Tree tree;

	void solve()
	{
		cin >> N;
		tree.add(0, 1);
		int shift = 0;
		ll x;
		for (int i = 0; i < N; i += 1) {
			int a;
			cin >> a;
			shift = posmod(shift - a, (int)MOD);
			x = 0;
			x += tree.get_sum(shift, tree.BASE, shift % 2);
			x += tree.get_sum(0, shift, 1 - (shift % 2));
			DBG(a, x);
			x %= MOD;
			tree.add(shift, x);
		}
		cout << x << '\n';
	}
};


Solve sol;

void solve()
{
	sol.solve();
}

int main()
{
	MAGIC;

	solve();
}