void merge(vll &L, vll &R, vll &A){ ll i=0,j=0,k=0,iL,jL; iL = L.size(); jL = R.size(); while(i<iL && j<jL ){ if(L[i]<=R[j]){ A[k] = L[i]; i++; } else if(R[j]<=L[i]){ A[k] = R[j]; j++; } k++; } while(i<iL){ A[k] = L[i]; i++; k++; } while(j<jL){ A[k] = R[j]; j++; k++; } return; }
vll matmul(const vll &A, const vll &B) { int m = A.size(); int n = B[0].size(); int x = B.size(); vll C(m, vector<long long>(n, 0)); for (int i=0; i<m; ++i) { for (int j=0; j<n; ++j) { for (int k=0; k<x; ++k) { C[i][j] = (C[i][j] + A[i][k]*B[k][j]) % mod; } } } return C; }
vll mul(const vll & va, const vll & vb) { int len = 32 - __builtin_clz(std::max(va.size(), vb.size()) - 1); len = 1 << (len + 1); vcd a(len), b(len); for (int i = 0; i < (int)va.size(); i++) a[i] = cd(va[i], 0); for (int i = 0; i < (int)vb.size(); i++) b[i] = cd(vb[i], 0); a = fft(a); b = fft(b); for (int i = 0; i < len; i++) { double real = a[i].real() * b[i].real() - a[i].imag() * b[i].imag(); a[i].imag() = a[i].imag() * b[i].real() + b[i].imag() * a[i].real(); a[i].real() = real; } a = fft(a, true); vll res(len); for (int i = 0; i < len; i++) res[i] = (long long)(a[i].real() + 0.5); return res; }
void all( vll& v, vll& l ) { for( int i = 0; i < v.size(); ++i ) { vll tmp, comb; for( vlli j = l.begin(); j != l.end(); ++j ) tmp.push_back( *j + v[ i ] ); for( vlli m = l.begin(), n = tmp.begin(); m != l.end() || n != tmp.end(); ) comb.push_back( n == tmp.end() || m != l.end() && *m <= *n? *m++ : *n++ ); l.swap( comb ); } }
ll solve(vll dat) { int sz=dat.size(); for(int i=1;i<sz;i++) { if(i==1) dat[i]=max(dat[i-1], dat[i]); else dat[i]=max(dat[i-1], dat[i]+dat[i-2]); } return dat[sz-1]; }
vll matexp(vll A, int n) { int m = A.size(); vll ret = matunit(m); while (n > 0) { if (n & 1) { ret = matmul(ret, A); } A = matmul(A, A); n >>= 1; } return ret; }
int main() { LL i,n,ans,k; while(cin>>k>>str) { cnt.pb(0); for(i=0; i<str.size(); i++) { if(str[i]=='1') cnt.pb(i+1); } cnt.pb(str.size()+1); if(k>cnt.size()-2) { pr1(0); continue; } ans=0; if(k==0) { for(i=1;i<cnt.size();i++) { n=cnt[i]-cnt[i-1]-1; ans+=n*(n+1)/2; } } else { for(i=1; i<cnt.size()-k; i++) { ans+=(cnt[i]-cnt[i-1])*(cnt[i+k]-cnt[i+k-1]); } } pr1(ans); } return 0; }
vll merge_sort(vll S){ vll tempL,tempR; ll len = S.size(); if(len < 2 ) return S; // array is already sorted. Base case rep(i,len/2) tempL.pub(S[i]); repk(i,len/2,len) tempR.pub(S[i]); tempL = merge_sort(tempL); tempR = merge_sort(tempR); merge(tempL,tempR,S); return S; }
vll matadd(const vll &A, const vll &B) { int m = A.size(); int n = A[0].size(); vll C(m, vector<long long>(n, 0)); for (int i=0; i<m; ++i) { for (int j=0; j<n; ++j) { C[i][j] = A[i][j] + B[i][j]; if (C[i][j] >= mod) { C[i][j] -= mod; } } } return C; }
int main() { LL a,b,i,k; bool flag; gen(); while(scanf("%lld %lld",&a,&b)!=EOF) { flag=true; for(i=0; i<cont.size() && cont[i]<=a+b; i++) { if(cont[i]>=a && cont[i]<=a+b) printf("%lld\n",cont[i]),flag=false; } if(flag) printf("None\n"); } return 0; }
void init() { int i=0 , j; LL pnum=0 , p=1; sll st; sll::iterator it; for(i=0; i<plen; i++) { pnum = prm[i]; for(j=2; j<=40; j++) { //pnum = power(prm[i] , j); p=1; for(int k=1; k<=j; k++) { p*=pnum; if(p > mxhigh) break; } if(p < mxhigh) { st.insert(p); } } } //cerr << st.size(); for(it=st.begin() ; it!=st.end() ; ++it) { v.push_back(*it); } //for(i=0; i<100; i++) cout << v[i] << " "; //cout << v.size(); //cout << v[v.size()-1]; vlen = v.size(); }
int deal(){ weight.clear(); cin >> buf; int depth = 0; ll tmp; for (string::iterator ii = buf.begin(); ii != buf.end(); ii++){ switch (*ii){ case '[': { depth++; }break; case ']': { depth--; }break; case ',':break; default: { tmp = 0; while ('0' <= *ii && *ii <= '9') tmp = tmp * 10 + *ii - '0', ii++; ii--; weight.push_back(tmp << depth); } } } sort(weight.begin(), weight.end()); int len = weight.size(); int best = 0, cur = 1; weight.push_back(-1); for (int i = 0; i < len; i++){ if (weight[i + 1] != weight[i]){ best = max(best, cur); cur = 1; } else cur++; } return len - best; }
static vll karatsubaMultiply(const vll &a, const vll &b) { int n = a.size(); vll res(n + n); if (n <= 32) { for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) res[i + j] += a[i] * b[j]; return std::move(res); } int k = n >> 1; vll a1(a.begin(), a.begin() + k); vll a2(a.begin() + k, a.end()); vll b1(b.begin(), b.begin() + k); vll b2(b.begin() + k, b.end()); vll a1b1 = karatsubaMultiply(a1, b1); vll a2b2 = karatsubaMultiply(a2, b2); for (int i = 0; i < k; i++) a2[i] += a1[i]; for (int i = 0; i < k; i++) b2[i] += b1[i]; vll r = karatsubaMultiply(a2, b2); for (int i = 0; i < (int)a1b1.size(); i++) r[i] -= a1b1[i]; for (int i = 0; i < (int)a2b2.size(); i++) r[i] -= a2b2[i]; for (int i = 0; i < (int)r.size(); i++) res[i + k] += r[i]; for (int i = 0; i < (int)a1b1.size(); i++) res[i] += a1b1[i]; for (int i = 0; i < (int)a2b2.size(); i++) res[i + n] += a2b2[i]; return std::move(res); }