//Konrad Paluszek,University of Warsaw(former XIV LO Staszic) //#STAY AT HOME #ifndef LOCAL #pragma GCC optimize("O3") #endif #define TIME (chrono::steady_clock::now().time_since_epoch().count()) #include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #define xfm(a,b)a##b #define xwb(a,b)xfm(a,b) #define _ xwb(nvj,__LINE__) #define __ xwb(kjy,__LINE__) #define ___ xwb(cjm,__LINE__) #define REP(i,n)for(urs(n)i=0;i<(n);++i) #define PER(r...)for(bool _=1;_||next_permutation(r);_=false) #define FS(r)r.first,r.second #define ALL(r)(r).begin(),(r).end() #define M0(r) memset(r,0,sizeof(r)) #define sim template<class c #define forbits(i,m)if(m)for(urs(m)i=ctz(m),i##nvj=m;i##nvj;i##nvj^=((urs(m))1<<i),i=i##nvj?ctz(i##nvj):0) #define fordbits(i,m)if(m)for(urs(m)i=8*sizeof(m)-clz(m)-1,i##nxd=m;i##nxd;i##nxd^=((urs(m))1<<i),i=i##nxd?8*sizeof(m)-clz(i##nxd)-1:0) #define ksets(t, m, k, n)for(t m=(((t)1<<(k))-1);m<((t)1<<(n));m=nux(m)) #define urs(r...)typename decay<decltype(r)>::type #define hur(f,g)sim>int f(c a){if(sizeof(c)==8)return g##ll(a);return g(a);} using namespace __gnu_pbds;using namespace std;using ll=long long;using ld=long double;using ull=unsigned long long;using vi=vector<int>;using vll=vector<ll>;using pii=pair<int,int>;using pll=pair<ll,ll>;using vpii=vector<pii>;using unt=unsigned int;sim>using min_queue=priority_queue<c,vector<c>,greater<>>;sim,class b,class cmp=less<c>>using ordered_map=tree<c,b,cmp,rb_tree_tag,tree_order_statistics_node_update>;sim,class cmp=less<c>>using ordered_set=ordered_map<c,null_type,cmp>;hur(popc,__builtin_popcount)hur(ctz,__builtin_ctz)hur(clz,__builtin_clz)sim,class N>bool mini(c&o,const N&h){if(o>h)return o=h,1;return 0;}sim,class N>bool maxi(c&o,const N&h){if(o<h)return o=h,1;return 0;} #ifdef LOCAL #include </home/konrad/cp/headers/debuglib.hpp> #else #define loc(...) #define onl(r...)r #define debug(...) #define print_stack(...) #define mark_stack(...) #define set_pre(...) #define reg_it(...) #define def_op(...) struct _{}; #define mask_set(...) #define exit my_exit void __resources(); void my_exit(int x) {fflush(stdout); #ifdef LOCAL2 __resources(); #endif _Exit(x);} #endif #define next nexT #define prev preV #define tree trEE #define left lefT #define right righT #define div diV #define y1 y_1 #define pow don't' ull mix(ull o){o+=0x9e3779b97f4a7c15;o=(o^(o>>30))*0xbf58476d1ce4e5b9;o=(o^(o>>27))*0x94d049bb133111eb;return o^(o>>31);}ull SALT=0x7a14a4b0881ebf9,tqu=0x7a14a4b0881ebf9;ull my_rand(){return tqu=mix(tqu);}void my_srand(ull x){SALT=tqu=x;}const int inf=1023400000;const ll llinf=1234567890000000000ll;ll fix(ll o, ll m){o%=m;if(o<0)o+=m;return o;} #define rand my_rand #define srand my_srand #define random_shuffle(r...)random_shuffle(r,[](int _){return my_rand()%_;}) sim>inline c nux(c m){if(!m)return numeric_limits<c>::max();c A=m&-m;c B=~((A-1)^m);c C=B&-B;c D=(C>>(1+ctz(A)))-1;return C|(m&~(C-1))|D;}sim>void unq(c&x){x.resize(unique(ALL(x))-x.begin());} //#STAY AT HOME const int mod = 1e9 + 7; #undef tree #define root this->node_begin() #define none this->node_end() #define V get_metadata().in #define L get_l_child() #define R get_r_child() //struct Mal potrzebny tylko jesli Op::T ma nietrywialny konstruktor template <class c> struct Mal : allocator<c> { template <class U> struct rebind { using other = Mal<U>; }; }; template <class...c> struct Mal<detail::rb_tree_node_<c...> > : allocator<detail::rb_tree_node_<c...> > { using v = typename Mal::value_type; v* allocate(int) { v* ans = allocator<v>::allocate(1); new (&ans->get_metadata()) typename v::metadata_type; return ans; } }; //Jesli nie potrzebujemy find_by_order i order_of_key, to wystarczy: // template <class c> struct Baz {mutable c in;}; //i wszedzie dalej pomijamy parametr bool ord, oraz w update wyroznione linie template <class c, bool b> struct Baz { mutable int size; mutable c in; operator int() const {return size;} void reset() const {size = 1;} void inc(int x) const {size += x;} }; template <class c> struct Baz <c, 0> { mutable c in; void reset() const {} void inc(const Baz&) const {} }; template <class Op, bool ord> struct Foo { //W C++11/14 trzeba: template <class A, class B, class C, class D> struct Bar : tree_order_statistics_node_update<A,B,C,D> { template <class... X> struct Bar : tree_order_statistics_node_update<X...> { using T = typename Op::T; using metadata_type = Baz<T, ord>; template <class c, class d> void operator()(c n, d end) const { n.V = Op::conv(**n); n.get_metadata().reset(); //Tylko jak potrzebujemy ordered_seta auto l = n.L, r = n.R; if (l != end) { n.V = Op::mer(l.V, n.V); n.get_metadata().inc(l.get_metadata()); //j.w. } if (r != end) { n.V = Op::mer(n.V, r.V); n.get_metadata().inc(r.get_metadata()); //j.w. } } }; }; template <class c, class k, class Op, class cmp = less<c>, bool ord = false> struct seg_map : tree<c, k, cmp, rb_tree_tag, Foo<Op, ord>::template Bar, Mal<c>> { //Jesli nie uzywamy structa Mal, to po prostu pomijamy ostatni parametr using T = typename Op::T; using C = typename seg_map::const_iterator; using N = typename seg_map::node_const_iterator; T mer(const T&a, const T&b, bool d) const { return d ? Op::mer(a, b) : Op::mer(b, a); } N go(N n, bool d) const {return d ? n.R : n.L;} T whole() const { return this->empty() ? Op::neu() : root.V; } T read(C it, bool d) const { N n = from_it(it); T ans = Op::neu(); if (go(n, d) != none) ans = go(n, d).V; while (n != root) { N p = P(n); if (go(p, !d) == n) { ans = mer(ans, Op::conv(**p), d); if (go(p, d) != none) ans = mer(ans, go(p, d).V, d); } n = p; } return ans; } T read_pref(C it) const {//[begin, it) if (it == this->begin()) return Op::neu(); if (it == this->end()) return whole(); return read(it, 0); } T read_suf(C it) const {//[it, end) if (it == this->begin()) return whole(); if (it == this->end()) return Op::neu(); return read(--it, 1); } //Dla l > r wynik jest nieokreslony, ale wykona sie w O(log n) i nie bedzie RE T read(C l, C r) const { //[l, r) if (l == this->begin()) return read_pref(r); if (r == this->end()) return read_suf(l); N b = from_it(--l), e = from_it(r); T B = Op::neu(), E = Op::neu(); if (!anc(b, e) && e.L != none) E = e.L.V; if (!anc(e, b) && b.R != none) B = b.R.V; int d = dep(b) - dep(e); while (b != e) { bool D = d > 0; D ? d-- : d++; N &m = D ? b : e, &o = D ? e : b; T &v = D ? B : E; N p = P(m); if (p != o && go(p, !D) == m) { v = mer(v, Op::conv(**p), D); N u = go(p, D); if (u != none && u != o) v = mer(v, u.V, D); } m = p; } return mer(B, E, 1); } N P(N x) const {return {x.m_p_nd->m_p_parent};} N from_it(C x) const {return {x.m_p_nd};} int dep(N x) const { int ans = 0; while (x != root) { ans++; x = P(x); } return ans; } bool anc(N x, N y) const { for (;;) { if (x == y) return 1; if (x == root) return 0; x = P(x); } } template <class Fun> C get_side(C it, Fun pred, bool dir) const { T acc = Op::neu(); N n = from_it(it); for (;;) { acc = mer(acc, **n, dir); if (!pred(acc)) return dir ? *n : ++*n; if (go(n, dir) != none) { T t1 = mer(acc, go(n, dir).V, dir); if (pred(t1)) acc = t1; else { n = go(n, dir); for (;;) { if (go(n, !dir) != none) { T t2 = mer(acc, go(n, !dir).V, dir); if (!pred(t2)) { n = go(n, !dir); continue; } acc = t2; } acc = mer(acc, **n, dir); if (!pred(acc)) return dir ? *n : ++*n; n = go(n, dir); } } } for (;;) { if (n == root) return dir ? this->end() : this->begin(); N p = P(n); if (go(p, !dir) == n) { n = p; break; } n = p; } } } //Zwraca najdalszy it taki, ze pred(read(beg, it)), lub it = beg, jesli takiego nie ma. Zaklada, ze jesli jakis przedzial spelnia pred, to jego podprzedzial tez template <class Fun> C get_right(C beg, Fun pred) const { if (beg == this->end()) return beg; return get_side(beg, pred, 1); } template <class Fun> C get_left(C end, Fun pred) const { //j.w, tylko z read(it, end) if (end == this->begin()) return end; return get_side(--end, pred, 0); } //Jesli wartosci agregowane zaleza od typu ta ktory jest mapowanie, to po kazdej edycji wartosci (takze wrzuceniu nowej) nalezy wywolac update lub po wszystkich edycjach wywolac update_all void update(C pos) { N n = from_it(pos); for (;;) { seg_map::node_update::operator()(n, none); if (n == root) break; n = P(n); } } void dfs(N n) { if (n == none) return; dfs(n.L); dfs(n.R); seg_map::node_update::operator()(n, none); } void update_all() { dfs(root); } }; template <class c, class Op, class cmp=less<c>, bool ord = false> using seg_set = seg_map<c, null_type, Op, cmp, ord>; struct Sum { //Przykladowy typ definiujacy operacje using T = array<ll, 2>; //typ wyniku dla przedzialu static T neu() {return {0, 0};}; //element neutralny dzialania //rzutuje typ wartosci na typ wynikowy (w przypadku mapy para: klucz, wartosc) static T conv(pii x) { return x.first % 2 ? T{0, x.second} : T{x.second, 0}; } static T mer(T a, T b) {return {(a[0] + b[0]) % mod, (a[1] + b[1]) % mod};} }; //Zeby sie skompilowalo z flaga -D_GLIBCXX_DEBUG, to typ trzymany w kontenerze (tylko typ klucza dla mapy) musi miec zdefiniowany operator<<(ostream &, nasz_typ), przy czym, jesli ten typ jest w namespace std, to operator tez musi byc. void solve() { int n; scanf("%d", &n); seg_map<int, int, Sum> dp; auto inc = [&](int x, int val) { auto [it, added] = dp.insert(pii(x, val)); if (!added) (it->second += val) %= mod; dp.update(it); }; inc(0, 1); int sum = 0; REP(i, n) { int x; scanf("%d", &x); (sum += x) %= mod; auto it = dp.upper_bound(sum); auto bef = dp.read(dp.begin(), it); auto whole = dp.whole(); int curr = fix(bef[sum & 1] + whole[(sum & 1) ^ 1] - bef[(sum & 1) ^ 1], mod); debug(imie(x), imie(sum), imie(dp), imie(bef), imie(whole), imie(curr)); if (i == n - 1) printf("%d\n", curr); else inc(sum, curr); } } int main() { // unt seed = TIME; debug(imie(seed));srand(seed); int t = 1; // scanf("%d", &t); REP(_, t) solve(); exit(0); } //#STAY AT HOME
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 | //Konrad Paluszek,University of Warsaw(former XIV LO Staszic) //#STAY AT HOME #ifndef LOCAL #pragma GCC optimize("O3") #endif #define TIME (chrono::steady_clock::now().time_since_epoch().count()) #include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #define xfm(a,b)a##b #define xwb(a,b)xfm(a,b) #define _ xwb(nvj,__LINE__) #define __ xwb(kjy,__LINE__) #define ___ xwb(cjm,__LINE__) #define REP(i,n)for(urs(n)i=0;i<(n);++i) #define PER(r...)for(bool _=1;_||next_permutation(r);_=false) #define FS(r)r.first,r.second #define ALL(r)(r).begin(),(r).end() #define M0(r) memset(r,0,sizeof(r)) #define sim template<class c #define forbits(i,m)if(m)for(urs(m)i=ctz(m),i##nvj=m;i##nvj;i##nvj^=((urs(m))1<<i),i=i##nvj?ctz(i##nvj):0) #define fordbits(i,m)if(m)for(urs(m)i=8*sizeof(m)-clz(m)-1,i##nxd=m;i##nxd;i##nxd^=((urs(m))1<<i),i=i##nxd?8*sizeof(m)-clz(i##nxd)-1:0) #define ksets(t, m, k, n)for(t m=(((t)1<<(k))-1);m<((t)1<<(n));m=nux(m)) #define urs(r...)typename decay<decltype(r)>::type #define hur(f,g)sim>int f(c a){if(sizeof(c)==8)return g##ll(a);return g(a);} using namespace __gnu_pbds;using namespace std;using ll=long long;using ld=long double;using ull=unsigned long long;using vi=vector<int>;using vll=vector<ll>;using pii=pair<int,int>;using pll=pair<ll,ll>;using vpii=vector<pii>;using unt=unsigned int;sim>using min_queue=priority_queue<c,vector<c>,greater<>>;sim,class b,class cmp=less<c>>using ordered_map=tree<c,b,cmp,rb_tree_tag,tree_order_statistics_node_update>;sim,class cmp=less<c>>using ordered_set=ordered_map<c,null_type,cmp>;hur(popc,__builtin_popcount)hur(ctz,__builtin_ctz)hur(clz,__builtin_clz)sim,class N>bool mini(c&o,const N&h){if(o>h)return o=h,1;return 0;}sim,class N>bool maxi(c&o,const N&h){if(o<h)return o=h,1;return 0;} #ifdef LOCAL #include </home/konrad/cp/headers/debuglib.hpp> #else #define loc(...) #define onl(r...)r #define debug(...) #define print_stack(...) #define mark_stack(...) #define set_pre(...) #define reg_it(...) #define def_op(...) struct _{}; #define mask_set(...) #define exit my_exit void __resources(); void my_exit(int x) {fflush(stdout); #ifdef LOCAL2 __resources(); #endif _Exit(x);} #endif #define next nexT #define prev preV #define tree trEE #define left lefT #define right righT #define div diV #define y1 y_1 #define pow don't' ull mix(ull o){o+=0x9e3779b97f4a7c15;o=(o^(o>>30))*0xbf58476d1ce4e5b9;o=(o^(o>>27))*0x94d049bb133111eb;return o^(o>>31);}ull SALT=0x7a14a4b0881ebf9,tqu=0x7a14a4b0881ebf9;ull my_rand(){return tqu=mix(tqu);}void my_srand(ull x){SALT=tqu=x;}const int inf=1023400000;const ll llinf=1234567890000000000ll;ll fix(ll o, ll m){o%=m;if(o<0)o+=m;return o;} #define rand my_rand #define srand my_srand #define random_shuffle(r...)random_shuffle(r,[](int _){return my_rand()%_;}) sim>inline c nux(c m){if(!m)return numeric_limits<c>::max();c A=m&-m;c B=~((A-1)^m);c C=B&-B;c D=(C>>(1+ctz(A)))-1;return C|(m&~(C-1))|D;}sim>void unq(c&x){x.resize(unique(ALL(x))-x.begin());} //#STAY AT HOME const int mod = 1e9 + 7; #undef tree #define root this->node_begin() #define none this->node_end() #define V get_metadata().in #define L get_l_child() #define R get_r_child() //struct Mal potrzebny tylko jesli Op::T ma nietrywialny konstruktor template <class c> struct Mal : allocator<c> { template <class U> struct rebind { using other = Mal<U>; }; }; template <class...c> struct Mal<detail::rb_tree_node_<c...> > : allocator<detail::rb_tree_node_<c...> > { using v = typename Mal::value_type; v* allocate(int) { v* ans = allocator<v>::allocate(1); new (&ans->get_metadata()) typename v::metadata_type; return ans; } }; //Jesli nie potrzebujemy find_by_order i order_of_key, to wystarczy: // template <class c> struct Baz {mutable c in;}; //i wszedzie dalej pomijamy parametr bool ord, oraz w update wyroznione linie template <class c, bool b> struct Baz { mutable int size; mutable c in; operator int() const {return size;} void reset() const {size = 1;} void inc(int x) const {size += x;} }; template <class c> struct Baz <c, 0> { mutable c in; void reset() const {} void inc(const Baz&) const {} }; template <class Op, bool ord> struct Foo { //W C++11/14 trzeba: template <class A, class B, class C, class D> struct Bar : tree_order_statistics_node_update<A,B,C,D> { template <class... X> struct Bar : tree_order_statistics_node_update<X...> { using T = typename Op::T; using metadata_type = Baz<T, ord>; template <class c, class d> void operator()(c n, d end) const { n.V = Op::conv(**n); n.get_metadata().reset(); //Tylko jak potrzebujemy ordered_seta auto l = n.L, r = n.R; if (l != end) { n.V = Op::mer(l.V, n.V); n.get_metadata().inc(l.get_metadata()); //j.w. } if (r != end) { n.V = Op::mer(n.V, r.V); n.get_metadata().inc(r.get_metadata()); //j.w. } } }; }; template <class c, class k, class Op, class cmp = less<c>, bool ord = false> struct seg_map : tree<c, k, cmp, rb_tree_tag, Foo<Op, ord>::template Bar, Mal<c>> { //Jesli nie uzywamy structa Mal, to po prostu pomijamy ostatni parametr using T = typename Op::T; using C = typename seg_map::const_iterator; using N = typename seg_map::node_const_iterator; T mer(const T&a, const T&b, bool d) const { return d ? Op::mer(a, b) : Op::mer(b, a); } N go(N n, bool d) const {return d ? n.R : n.L;} T whole() const { return this->empty() ? Op::neu() : root.V; } T read(C it, bool d) const { N n = from_it(it); T ans = Op::neu(); if (go(n, d) != none) ans = go(n, d).V; while (n != root) { N p = P(n); if (go(p, !d) == n) { ans = mer(ans, Op::conv(**p), d); if (go(p, d) != none) ans = mer(ans, go(p, d).V, d); } n = p; } return ans; } T read_pref(C it) const {//[begin, it) if (it == this->begin()) return Op::neu(); if (it == this->end()) return whole(); return read(it, 0); } T read_suf(C it) const {//[it, end) if (it == this->begin()) return whole(); if (it == this->end()) return Op::neu(); return read(--it, 1); } //Dla l > r wynik jest nieokreslony, ale wykona sie w O(log n) i nie bedzie RE T read(C l, C r) const { //[l, r) if (l == this->begin()) return read_pref(r); if (r == this->end()) return read_suf(l); N b = from_it(--l), e = from_it(r); T B = Op::neu(), E = Op::neu(); if (!anc(b, e) && e.L != none) E = e.L.V; if (!anc(e, b) && b.R != none) B = b.R.V; int d = dep(b) - dep(e); while (b != e) { bool D = d > 0; D ? d-- : d++; N &m = D ? b : e, &o = D ? e : b; T &v = D ? B : E; N p = P(m); if (p != o && go(p, !D) == m) { v = mer(v, Op::conv(**p), D); N u = go(p, D); if (u != none && u != o) v = mer(v, u.V, D); } m = p; } return mer(B, E, 1); } N P(N x) const {return {x.m_p_nd->m_p_parent};} N from_it(C x) const {return {x.m_p_nd};} int dep(N x) const { int ans = 0; while (x != root) { ans++; x = P(x); } return ans; } bool anc(N x, N y) const { for (;;) { if (x == y) return 1; if (x == root) return 0; x = P(x); } } template <class Fun> C get_side(C it, Fun pred, bool dir) const { T acc = Op::neu(); N n = from_it(it); for (;;) { acc = mer(acc, **n, dir); if (!pred(acc)) return dir ? *n : ++*n; if (go(n, dir) != none) { T t1 = mer(acc, go(n, dir).V, dir); if (pred(t1)) acc = t1; else { n = go(n, dir); for (;;) { if (go(n, !dir) != none) { T t2 = mer(acc, go(n, !dir).V, dir); if (!pred(t2)) { n = go(n, !dir); continue; } acc = t2; } acc = mer(acc, **n, dir); if (!pred(acc)) return dir ? *n : ++*n; n = go(n, dir); } } } for (;;) { if (n == root) return dir ? this->end() : this->begin(); N p = P(n); if (go(p, !dir) == n) { n = p; break; } n = p; } } } //Zwraca najdalszy it taki, ze pred(read(beg, it)), lub it = beg, jesli takiego nie ma. Zaklada, ze jesli jakis przedzial spelnia pred, to jego podprzedzial tez template <class Fun> C get_right(C beg, Fun pred) const { if (beg == this->end()) return beg; return get_side(beg, pred, 1); } template <class Fun> C get_left(C end, Fun pred) const { //j.w, tylko z read(it, end) if (end == this->begin()) return end; return get_side(--end, pred, 0); } //Jesli wartosci agregowane zaleza od typu ta ktory jest mapowanie, to po kazdej edycji wartosci (takze wrzuceniu nowej) nalezy wywolac update lub po wszystkich edycjach wywolac update_all void update(C pos) { N n = from_it(pos); for (;;) { seg_map::node_update::operator()(n, none); if (n == root) break; n = P(n); } } void dfs(N n) { if (n == none) return; dfs(n.L); dfs(n.R); seg_map::node_update::operator()(n, none); } void update_all() { dfs(root); } }; template <class c, class Op, class cmp=less<c>, bool ord = false> using seg_set = seg_map<c, null_type, Op, cmp, ord>; struct Sum { //Przykladowy typ definiujacy operacje using T = array<ll, 2>; //typ wyniku dla przedzialu static T neu() {return {0, 0};}; //element neutralny dzialania //rzutuje typ wartosci na typ wynikowy (w przypadku mapy para: klucz, wartosc) static T conv(pii x) { return x.first % 2 ? T{0, x.second} : T{x.second, 0}; } static T mer(T a, T b) {return {(a[0] + b[0]) % mod, (a[1] + b[1]) % mod};} }; //Zeby sie skompilowalo z flaga -D_GLIBCXX_DEBUG, to typ trzymany w kontenerze (tylko typ klucza dla mapy) musi miec zdefiniowany operator<<(ostream &, nasz_typ), przy czym, jesli ten typ jest w namespace std, to operator tez musi byc. void solve() { int n; scanf("%d", &n); seg_map<int, int, Sum> dp; auto inc = [&](int x, int val) { auto [it, added] = dp.insert(pii(x, val)); if (!added) (it->second += val) %= mod; dp.update(it); }; inc(0, 1); int sum = 0; REP(i, n) { int x; scanf("%d", &x); (sum += x) %= mod; auto it = dp.upper_bound(sum); auto bef = dp.read(dp.begin(), it); auto whole = dp.whole(); int curr = fix(bef[sum & 1] + whole[(sum & 1) ^ 1] - bef[(sum & 1) ^ 1], mod); debug(imie(x), imie(sum), imie(dp), imie(bef), imie(whole), imie(curr)); if (i == n - 1) printf("%d\n", curr); else inc(sum, curr); } } int main() { // unt seed = TIME; debug(imie(seed));srand(seed); int t = 1; // scanf("%d", &t); REP(_, t) solve(); exit(0); } //#STAY AT HOME |