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
// Grzegorz Ryn
// V LO Kraków

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define st first
#define nd second
#define FOR(__VAR, __START, __END) for(int __VAR=__START; __VAR<=__END; __VAR++)
#define FORB(__VAR, __START, __END) for(int __VAR=__START; __VAR>=__END; __VAR--)
#define FORK(__VAR, __START, __END, __DIFF) for(int __VAR=__START; __VAR<=END; __VAR+=__DIFF)
#define all(__VAR) (__VAR).begin(), (__VAR).end()
#define rall(__VAR) (__VAR).rbegin(), (__VAR).rend()
#define DEBUG(__VAR) cout << #__VAR << ": " << __VAR << endl;

template<typename __T1, typename __T2>
ostream & operator<<(ostream &out, pair<__T1, __T2> &__VAR) {
	cout << "[" << __VAR.st << ", " << __VAR.nd << "]";
	return out;
}

template<typename __T>
ostream & operator<<(ostream &out, vector<__T> &__VAR) {
	cout << "[";
	FOR(i, 0, (int)__VAR.size()-2)
		cout << __VAR[i] << ", ";
	if(__VAR.size()>0)
		cout << __VAR[__VAR.size()-1];
	cout << "]" << endl;
	
	return out;
}

const ll M = 1'000'000'000 + 7;

struct segmentTree {
	struct Node {
		Node *left = NULL, *right = NULL;
		array<ll,2> sum = {0,0};
		
		~Node() {
			delete left;
			delete right;
		}
	};
	
	
	ll N = 1LL<<30;
	Node Root;
	
	segmentTree() {}
	
	void make_node(Node*& root) {
		if(root != NULL) {
			return;
		}
		root = new Node;
	}
	
	void merge(Node* root) {
		make_node(root->left);
		make_node(root->right);
		for(int r=0; r<2; r++) {
			root->sum[r] = root->left->sum[r] + root->right->sum[r];
		}
	}
	
	void insert(Node* root, ll l, ll r, ll pos, ll val) {
		if(pos < l || r < pos) {
			return;
		}
		if(l == r) {
			root->sum[l%2] += val;
			root->sum[l%2] %= M;
			return;
		}
		ll mid = (l+r)/2;
		make_node(root->left);
		insert(root->left, l, mid, pos, val);
		make_node(root->right);
		insert(root->right, mid+1, r, pos, val);
		merge(root);
	}
	
	array<ll,2> query(Node* root, ll l, ll r, ll p, ll q) {
		if(q<l || r<p) {
			return {0,0};
		}
		if(p<=l && r<=q) {
			return root->sum;
		}
		ll mid = (l+r)/2;
		
		make_node(root->left);
		auto L = query(root->left, l, mid, p, q);
		make_node(root->right);
		auto R = query(root->right, mid+1, r, p, q);
		
		for(int r=0; r<2; r++) {
			L[r] = (L[r] + R[r]) % M;
		}		
		return L;
	}
	
	void add(ll pos, ll val) {
		insert(&Root, 0, N-1, pos, val);
	}
	
	array<ll,2> sum(ll p, ll q) {
		return query(&Root, 0, N-1, p, q);
	}
};

ll solve() {
	ll N;
	cin >> N;
	vector<ll> a(N);
	for(int i=0; i<N; i++) {
		cin >> a[i];
	}
	
	ll offset = 0;
	segmentTree dp;
	
	auto get_sum = [&](ll p, ll q, int r) {
		if(offset%2 == 1) {
			r = 1-r;
		}
		
		if(p < offset) {
			if(q < offset) {
				return dp.sum(p-offset+M, q-offset+M)[1-r];
			}
			else {
				return (dp.sum(p-offset+M, M-1)[1-r] + dp.sum(0, q-offset)[r])%M;
			}
		}
		else {
			return dp.sum(p-offset, q-offset)[r];
		}
	};
	
	dp.add(a[0], 1);
	for(int i=1; i<N; i++) {
		ll sum = get_sum(0, M-1, 0);
		offset = (offset + a[i])%M;
		dp.add((a[i]-offset+M) % M, sum);
	}
	
	return get_sum(0, M-1, 0);
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cout << solve() << '\n';

	return 0;
}