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
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mod 1000000007
vector<ll> tree_odd;
vector<ll> tree_even;
vector<ll> even_sort;
vector<ll> odd_sort;
vector<int> V;
vector<ll> sum;
vector<ll> ans;
set<ll> even;
set<ll> odd;

void AddOdd(const ll &res, size_t node) {
  while (node > 0) {
    tree_odd[node] += res;
    if (tree_odd[node] >= mod) tree_odd[node] -= mod;
    node >>= 1;
  }
}

ll FindEvenIndex(ll num) {
  ll node = -1;
  for (size_t b = max((size_t)1, even_sort.size() >> 1); b > 0; b >>= 1) {
    while (node + b < even_sort.size() && even_sort[node + b] <= num) {
      node += b;
    }
  }
  return node;
}

ll FindOddIndex(ll num) {
  ll node = -1;
  for (size_t b = max((size_t)1, odd_sort.size() >> 1); b > 0; b >>= 1) {
    while (node + b < odd_sort.size() && odd_sort[node + b] <= num) {
      node += b;
    }
  }
  return node;
}

void AddEven(const ll &res, size_t node) {
  while (node > 0) {
    tree_even[node] += res;
    if (tree_even[node] >= mod)  tree_even[node] -= mod;
    node >>= 1;
  }
}

ll Even(ll R) {
  R = FindEvenIndex(R) + (tree_even.size() >> 1);
  if (R - (ll)(tree_even.size() >> 1) < 0) {
    return 0;
  }
  ll res = 0;
  if ((R & 1) == 0) {
    res += tree_even[R];
  } else {
    res += tree_even[R] + tree_even[R - 1];
  }
  if (res >= mod) res -= mod;
  R >>= 1;
  while (R) {
    if (R & 1) {
      res += tree_even[R - 1];
      if (res >= mod) res -= mod;;
    }
    R >>= 1;
  }
  return res;
}

ll Odd(ll R) {
  R = FindOddIndex(R) + (tree_odd.size() >> 1);
  if (R - (ll)(tree_odd.size() >> 1) < 0) {
    return 0;
  }
  ll res = 0;
  if ((R & 1) == 0) {
    res += tree_odd[R];
  } else {
    res += tree_odd[R] + tree_odd[R - 1];
  }
  if (res >= mod) res -= mod;
  R >>= 1;
  while (R) {
    if (R & 1) {
      res += tree_odd[R - 1];
      if (res >= mod) res -= mod;
    }
    R >>= 1;
  }
  return res;
}

void Add(const ll &res, ll s) {
  if (s & 1) {
    AddOdd(res, FindOddIndex(s) + (tree_odd.size() >> 1));
  } else {
    AddEven(res, FindEvenIndex(s) + (tree_even.size() >> 1));
  }
}

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

  int nums;
  cin >> nums;
  V.resize(nums);
  sum.resize(nums + 1);
  sum[0] = 0;
  ans.resize(nums + 1);
  even.insert(0);

  for (int i = 0; i < nums; i++) {
    cin >> V[i];
  }
  for (int i = 0; i < V.size(); i++) {
    sum[i + 1] = sum[i] + V[i];
    if (sum[i + 1] >= mod) sum[i + 1] -= mod;
    if (sum[i + 1] & 1) odd.insert(sum[i + 1]);
    else even.insert(sum[i + 1]);
  }

  even_sort.reserve(even.size());
  odd_sort.reserve(odd.size());

  for (auto const & i : even) {
    even_sort.push_back(i);
  }
  for (auto const &i : odd) {
    odd_sort.push_back(i);
  }

  int k = 1;
  while (k < even_sort.size()) {
    k <<= 1;
  }
  tree_even.resize(k << 1, 0);
  k = 1;
  while (k < odd_sort.size()) {
    k <<= 1;
  }
  tree_odd.resize(k << 1, 0);

  ans[0] = 1;
  Add(1, 0);
  for (int i = 1; i < ans.size(); i++) {
    if (sum[i] & 1) {
      ans[i] += Odd(sum[i]) + tree_even[1] - Even(sum[i]);
      while (ans[i] >= mod) ans[i] -= mod;
      while (ans[i] < 0) ans[i] += mod;
    } else {
      ans[i] += Even(sum[i]) + tree_odd[1] - Odd(sum[i]);
      while (ans[i] >= mod) ans[i] -= mod;
      while (ans[i] < 0) ans[i] += mod;
    }
    if (ans[i]) Add(ans[i], sum[i]);
  }
  cout << ans.back() << "\n";
}