malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 10 * 100 * 1000 + 10;   vector<int> vec[N];   int bit[N];   int n, c;   void addbit(int i, int p) {     for (i++; i <= c; i += (i & -i)) bit[i] += p;   }   int get(int i) {     int x = 0;     for (i++; i > 0; i -= (i & -i)) x += bit[i];     return x;   }   void add(int l, int r) {     addbit(l, 1);     addbit(r, -1);   }   int main() {     cin >> n >> c;     for (int i = 0; i < n; i++) {       int t;       cin >> t;       for (int j = 0; j < t; j++) {         int a;         cin >> a;         vec[i].push_back(a - 1);       }     }     for (int i = 0; i < n - 1; i++) {       int j = 0, k = 0;       while (j < (int)vec[i].size() && k < (int)vec[i + 1].size() &&              vec[i][j] == vec[i + 1][k])         j++, k++;       if (j == (int)vec[i].size())         add(0, c);       else if (k == (int)vec[i + 1].size()) {         cout <<  -1 n ;         return 0;       } else {         int a = vec[i][j], b = vec[i + 1][k];         int li = (c - a) % c, ri = (c - b) % c;         if (li < ri)           add(li, ri);         else           add(li, c), add(0, ri);       }     }     for (int i = 0; i < c; i++)       if (get(i) >= n - 1) {         cout << i << endl;         return 0;       }     cout << -1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i;     scanf( %i , &n);     int a = n / 3, b = n - a;     for (i = 1; i <= b; i++) printf( 1 %i n , i);     for (i = 1; i <= a; i++) printf( 4 %i n , i * 2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   string s, ret;   bool dfs(int idx, int four, int seven, bool flag) {     if (idx == n) return true;     if (flag) {       for (int i = 0; i < four; i++) ret[idx + i] =  4 ;       for (int i = four; i < four + seven; i++) ret[idx + i] =  7 ;       return true;     }     if (four > 0 && s[idx] <=  4  &&         dfs(idx + 1, four - 1, seven, s[idx] <  4 )) {       ret[idx] =  4 ;       return true;     }     if (seven > 0 && s[idx] <=  7  &&         dfs(idx + 1, four, seven - 1, s[idx] <  7 )) {       ret[idx] =  7 ;       return true;     }     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> s;     n = s.length();     ret.resize(n);     if (n % 2 == 1 || !dfs(0, n / 2, n / 2, false)) {       int half = (n + 2) / 2;       for (int i = 0; i < half; i++) cout <<  4 ;       for (int i = 0; i < half; i++) cout <<  7 ;       cout <<   n ;     } else       cout << ret <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void Routine() {     srand(time(NULL));     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   template <class T, class U>   istream &operator>>(istream &in, pair<T, U> &p) {     in >> p.fi >> p.se;     return in;   }   template <class T, class U>   ostream &operator<<(ostream &out, const pair<T, U> &p) {     out << p.first <<     << p.second;     return out;   }   template <class T>   istream &operator>>(istream &in, vector<T> &v) {     for (auto &i : v) {       in >> i;     }     return in;   }   template <class T>   ostream &operator<<(ostream &out, const vector<T> &v) {     for (auto &i : v) {       out << i <<   n ;     }     return out;   }   const long long mod = 1e9 + 7;   int main() {     Routine();     long long q, l1, l2, r1, r2, i;     cin >> q;     for (i = 0; i < q; i++) {       cin >> l1 >> r1 >> l2 >> r2;       if (l1 != r2) {         cout << l1 <<     << r2 <<   n ;       } else {         cout << r1 <<     << l2 <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int mod = 1e9 + 7;   using namespace std::chrono;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n;     cin >> n;     string s;     cin >> s;     long long int a[26];     for (int i = 0; i < 26; i++) cin >> a[i];     long long int maxx = -1, len = 0, minn;     vector<long long int> dp(n + 1, 0), dp2(n + 1, 1e12);     for (int i = 0; i < n; i++) {       minn = 1e12;       for (int j = i; j >= 0; j--) {         len = i - j + 1;         minn = min(minn, a[s[j] -  a ]);         if (minn < len) break;         long long int x = j - 1 >= 0 ? dp[j - 1] : 1;         dp[i] = (dp[i] + x) % mod;         maxx = max(maxx, len);         x = j - 1 >= 0 ? dp2[j - 1] : 0;         dp2[i] = min(dp2[i], x + 1);       }     }     cout << dp[n - 1] % mod << endl << maxx << endl << dp2[n - 1];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<string> s;   vector<pair<int, int> > v;   int gf = 0;   int x[9] = {-1, -1, -1, 0, 1, 1, 1, 0, 0};   int y[9] = {-1, 0, 1, 1, 1, 0, -1, -1, 0};   void dfs(int a, int b, int le) {     if (gf) return;     if (le == 8 || (a == 0 && b == 7)) {       gf = 1;       return;     }     int a1, b1, i, j, k, x1, y1, flag, x2, y2;     for (i = 0; i < 9; i++) {       flag = 0;       a1 = a + x[i], b1 = b + y[i];       if (a1 >= 0 && a1 < 8 && b1 >= 0 && b1 < 8) {         for (k = 0; k < v.size(); k++) {           x1 = v[k].first + (le + 1);           y1 = v[k].second;           x2 = v[k].first + (le);           y2 = v[k].second;           if ((a1 == x1 && b1 == y1) || (a1 == x2 && b1 == y2)) flag = 1;         }         if (flag == 0) dfs(a1, b1, le + 1);       }     }   }   int main() {     string st;     int i;     for (i = 0; i < 8; i++) {       cin >> st;       s.push_back(st);     }     int j;     for (i = 0; i < 8; i++) {       for (j = 0; j < 8; j++) {         if (s[i][j] ==  S ) v.push_back(make_pair(i, j));       }     }     dfs(7, 0, 0);     if (gf)       cout <<  WIN             <<   n ;     else       cout <<  LOSE             <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Wall {     int l, r, t;     void init(int _l, int _r, int _t) { l = _l, r = _r, t = _t; }     void input() { scanf( %d%d%d , &l, &r, &t); }     static bool by_l(const Wall &a, const Wall &b) { return a.l < b.l; }     bool operator<(const Wall &a) const { return t > a.t; }   } w[500010], wc[500010];   struct Table {     int a[500010 * 2], top;     Table() { top = 0; }     void insert(int x) { a[top++] = x; }     void sort() {       std::sort(a, a + top);       top = unique(a, a + top) - a;     }     int search(int x) { return lower_bound(a, a + top, x) - a; }   } table;   struct Tri {     int x, p;     void init(int _x, int _p) { x = _x, p = _p; }     bool operator<(const Tri &a) const { return x < a.x; }   } tri[500010];   int q[500010];   int main() {     int n, m;     cin >> m >> n;     for (int i = 0; i < n; ++i) {       w[i].input();     }     for (int i = 0; i < m; ++i) {       scanf( %d , q + i);     }     sort(w, w + n, Wall::by_l);     for (int i = 0; i < n; ++i) {       table.insert(w[i].l), table.insert(w[i].r);     }     table.sort();     priority_queue<Wall> que;     int nc = 0;     for (int i = 0, j = 0; i < table.top - 1; ++i) {       while (j < n && w[j].l <= table.a[i]) {         que.push(w[j++]);       }       while (!que.empty()) {         Wall wall = que.top();         if (wall.r > table.a[i]) {           wc[nc++].init(table.a[i], table.a[i + 1], wall.t);           break;         }         que.pop();       }     }     int ntri = 0;     for (int i = 0; i < nc; ++i) {       tri[ntri++].init(wc[i].t - wc[i].r, 1);       tri[ntri++].init(wc[i].t - wc[i].l, -1);     }     sort(tri, tri + ntri);     int sgm = 0, cnt = 0;     for (int i = 0, j = 0; i < m; ++i) {       while (j < ntri && tri[j].x <= q[i]) {         cnt += tri[j].p;         sgm += tri[j].x * tri[j].p;         ++j;       }       printf( %d n , q[i] * cnt - sgm);     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     int a[200001];     int i;     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     long long buy = a[n - 1];     int pre = a[n - 1];     for (i = n - 2; i >= 0; i--) {       if (a[i] >= pre - 1) {         if (pre - 1 == 0)           break;         else           buy += pre - 1;         pre--;       } else {         buy += a[i];         pre = a[i];       }     }     printf( %lld n , buy);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     set<string> s;     s.insert( don t even );     s.insert( worse );     s.insert( terrible );     s.insert( no way );     s.insert( go die in a hole );     s.insert( are you serious );     int c = 0;     while (true) {       cout << c++ << endl;       string t;       getline(cin, t);       if (t !=  no ) {         if (s.count(t) == 0) {           cout <<  normal  << endl;           return 0;         } else {           cout <<  grumpy  << endl;           return 0;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int max = a[0];     int pos = 0;     for (int i = 0; i < n; i++) {       if (max < a[i]) {         max = a[i];         pos = i;       }     }     bool k = true;     for (int i = pos; i > 0; i--) {       if (a[i - 1] >= a[i]) {         k = false;       }     }     for (int i = pos; i < n - 1; i++) {       if (a[i] <= a[i + 1]) {         k = false;       }     }     if (k == true)       printf( YES n );     else       printf( NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<int>> sum;   vector<vector<bool>> used;   int n, m;   int g = 0;   int k = 0;   vector<pair<int, int>> p = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};   void dfs(int first, int second, const int &r1, const int &r2, const int &l1,            const int &l2) {     if (first <= r1 || first > r2 || second <= l1 || second > l2 ||         used[first][second])       return;     used[first][second] = true;     k++;     for (int i = 0; i < 4; i++)       dfs(first + p[i].first, second + p[i].second, r1, r2, l1, l2);   }   bool f(int r) {     r = r * 2 + 1;     k = 0;     for (int i = 0; i <= n; i++)       for (int j = 0; j <= m; j++) used[i][j] = false;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (i >= r && j >= r &&             sum[i][j] - sum[i - r][j] - sum[i][j - r] + sum[i - r][j - r] ==                 r * r) {           dfs(i, j, i - r, i, j - r, j);         }     if (k == g)       return true;     else       return false;   }   int main() {     cin >> n >> m;     sum.resize(n + 1, vector<int>(m + 1, 0));     used.resize(n + 1, vector<bool>(m + 1, 0));     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         char c;         cin >> c;         sum[i + 1][j + 1] = sum[i][j + 1] + sum[i + 1][j] - sum[i][j];         if (c ==  X ) sum[i + 1][j + 1]++;       }     g = sum.back().back();     int l = 0, r = min(n / 2 + 2, m / 2 + 2);     while (l + 1 < r) {       int c = (l + r) / 2;       if (f(c))         l = c;       else         r = c;     }     cout << l <<   n ;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (i >= l + 1 && j >= l + 1 && i + l <= n && j + l <= m &&             sum[i + l][j + l] - sum[i - l - 1][j + l] - sum[i + l][j - l - 1] +                     sum[i - l - 1][j - l - 1] ==                 (2 * l + 1) * (2 * l + 1))           cout <<  X ;         else           cout <<  . ;       }       cout <<   n ;     }     cin >> n;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     for (int i = 0; i < t; i++) {       int n;       cin >> n;       int sum = 0, odd = 0, even = 0;       for (int i = 0; i < n; i++) {         int x;         cin >> x;         if (x % 2 == 0) {           even++;         } else {           odd++;         }         sum += x;       }       if (sum % 2 == 1) {         cout <<  YES n ;       } else {         if (odd < n && odd > 0) {           cout <<  YES n ;         } else {           cout <<  NO n ;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = (int)1E9;   const long long LINF = (long long)1E18;   int INP, AM;   char BUF[(1 << 10) + 1], *inp = BUF;   template <typename T>   T gcd(T a, T b) {     return (b == 0) ? abs(a) : gcd(b, a % b);   }   template <typename T>   inline T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   template <typename T>   inline T sqr(T x) {     return x * x;   }   const char DEBUG_PARAM[] =  __LOCAL_TESTING ;   const char IN[] =  input.txt ;   const char OUT[] =  output.txt ;   int ntest = 0, test;   inline void init();   inline void run();   inline void stop() { ntest = test - 1; }   int main(int argc, char* argv[]) {     if (argc > 1 && strcmp(argv[1], DEBUG_PARAM) == 0) {       freopen(IN,  r , stdin);     }     init();     if (ntest == 0) {       puts( ntest = ? );       return 0;     }     for (test = 1; test <= ntest; test++) {       run();     }     return 0;   }   const int dx[] = {-1, 0, 0, 1};   const int dy[] = {0, -1, 1, 0};   const long double EPS = 1E-9;   const long long MODULO = 1000000007LL;   inline void init() { ntest = 1; }   double s;   void run() {     cin >> s;     double a, b, c;     cin >> a >> b >> c;     if (a == 0 && b == 0 && c == 0) {       cout <<  0 0 0 ;       return;     }     double sum = a + b + c;     printf( %.20lf %.20lf %.20lf , a / sum * s, b / sum * s, c / sum * s);   }
#include <bits/stdc++.h>   #include <iomanip>      // std::setprecision      #define ll long long   const long modulo=1000000007;      using namespace std;            int ctoi(char c) {return c- 0 ;}            int compare(pair <int,pair<int,int>> one, pair <int,pair<int,int>> two){    if(one.first<two.first) return 1;    return 0;   }      ll power(ll a, ll b){   ll res=1;   while(b!=0){      if(b%2==1){    res*=a;    //res%=modulo;   }   a*=a;   //a%=modulo;   b/=2;   }   return res;   }      int dp[501][501][21]={0};   int n,m,k;   int dn[501][501];   int rightt[501][501];      int explore(int q,int i,int j){      if(q==0){ return 0;   }      if(dp[i][j][q]!=0){    //cout<< 1 ;    return dp[i][j][q];   }    int ans = dp[i][j][k];   ans=INT_MAX;       if(j<m-1) ans=min(ans,explore(q-2,i,j+1) + 2*dn[i][j]);    if(j>0)ans=min(ans,explore(q-2,i,j-1) +2*dn[i][j-1]);    if(i<n-1)ans=min(ans,explore(q-2,i+1,j) +2*rightt[i][j]);    if(i>0)ans=min(ans,explore(q-2,i-1,j) +2*rightt[i-1][j]);          //ans=min(min(explore(d,r,n-2,i,j-1,dn,right) +2*dn[i][y0], explore(d,r,n-2,i,j+1,dn,right) +2*dn[i][y]),min(explore(d,r,n-2,i-1,j,dn,right)+2*right[x0][j], explore(d,r,n-2,i+1,j,dn,right)+2*right[x][j]));    dp[i][j][q]=ans;    return ans;            }         void solve()   {      cin>>n>>m>>k;            if(k%2!=0){      for(int i=0;i<n;i++){    for(int j=0;j<m;j++){          cout<< -1 <<   ;    }    cout<<endl;   }   return;   }      for(int i=0;i<n;i++){    for(int j=0;j<m-1;j++){     cin>>dn[i][j];    }      }      for(int i=0;i<n-1;i++){    for(int j=0;j<m;j++){     cin>>rightt[i][j];    }      }      int ans[501][501];      for(int i=0;i<n;i++){    for(int j=0;j<m;j++){     ans[i][j]=explore(k,i,j);     cout<<ans[i][j]<<   ;    }    cout<<endl;   }            }                        int main() {        #ifndef ONLINE_JUDGE        freopen( input.txt ,  r , stdin);        freopen( output.txt ,  w , stdout);     #endif    ios_base::sync_with_stdio(false);        cin.tie(NULL);            ll t=1;//cin>>t;   while(t--){      solve();      }         return 0;   }            //rememberhere
#include <bits/stdc++.h>   using namespace std;   long long ar[1005][1005], br[1005][1005], fr[555];   string s[555];   string s1, s2;   int main() {     long long i, j, k, m, n, r, c;     while (cin >> r >> c) {       getchar();       s[0] =   ;       for (i = 1; i <= r; i++) {         getline(cin, s[i]);       }       n = r;       if (n & 1) {         cout << n << endl;         continue;       }       while (n > 0) {         i = 1;         j = n;         while (s[i] == s[j]) {           i++, j--;           if (i > j) break;         }         if (i > j)           n /= 2;         else {           cout << n << endl;           return 0;         }         if (n & 1) {           cout << n << endl;           return 0;         }       }       cout << 1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int cnt[27][200010];   int main() {     string s;     int q, i, j, l, r, c;     cin >> s >> q;     memset(cnt, 0, sizeof(cnt));     for (i = 0; i < s.length(); i++) {       c = s[i] -  a ;       cnt[c][i + 1]++;       for (j = 0; j < 26; j++) cnt[j][i + 1] += cnt[j][i];     }     for (; q > 0; q--) {       scanf( %d%d , &l, &r);       if (l == r)         cout <<  Yes  << endl;       else {         if (s[l - 1] != s[r - 1])           cout <<  Yes  << endl;         else {           int sum = 0;           for (i = 0; i < 26; i++) {             if (cnt[i][r] - cnt[i][l - 1] >= 1) sum++;             if (sum == 3) break;           }           if (sum == 3)             cout <<  Yes  << endl;           else             cout <<  No  << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     bool palindrom = true;     for (int i = 0; i < ceil(s.length() / 2.0); i++) {       if (s[i] != s[s.length() - 1 - i]) palindrom = false;     }     if (!palindrom) {       cout << s.length() <<   n ;       return 0;     }     char elso = s[0];     bool mind_ugyanaz = true;     for (auto c : s) {       if (c != elso) mind_ugyanaz = false;     }     if (mind_ugyanaz)       cout <<  0 n ;     else       cout << s.length() - 1 <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, dfn[100010], siz[100010], tim, idfn[100010], a[100010], Q;   vector<int> v[100010];   inline int add(int a, int b) {     if ((a += b) >= m) a -= m;     return a;   }   void dfs(int np, int fath) {     dfn[np] = ++tim;     idfn[tim] = np;     siz[np] = 1;     for (auto &x : v[np]) {       if (x == fath) continue;       dfs(x, np);       siz[np] += siz[x];     }   }   bitset<1000> bas, prm;   inline void shift(bitset<1000> &bt, int v) {     if (!v) return;     bt = ((bt << v) | (bt >> (m - v))) & bas;   }   class sgt {    public:     bitset<1000> dat[400010];     int lzy[400010];     void pushnow(int p, int v) {       lzy[p] = add(lzy[p], v);       shift(dat[p], v);     }     void pushdown(int p) {       if (lzy[p]) {         pushnow((p << 1), lzy[p]);         pushnow(((p << 1) | 1), lzy[p]);         lzy[p] = 0;       }     }     void pushup(int p) { dat[p] = dat[(p << 1)] | dat[((p << 1) | 1)]; }     void build(int p, int l, int r) {       for (int i = l; i <= r; i++) dat[p].set(a[idfn[i]]);       if (l == r) return;       int mid = (l + r) >> 1;       build((p << 1), l, mid);       build(((p << 1) | 1), mid + 1, r);     }     void modify(int p, int l, int r, int ml, int mr, int v) {       if (ml <= l && r <= mr) {         pushnow(p, v);         return;       }       pushdown(p);       int mid = (l + r) >> 1;       if (ml <= mid) modify((p << 1), l, mid, ml, mr, v);       if (mr > mid) modify(((p << 1) | 1), mid + 1, r, ml, mr, v);       pushup(p);     }     void query(int p, int l, int r, int ql, int qr, bitset<1000> &q) {       if (ql <= l && r <= qr) {         q |= dat[p];         return;       }       pushdown(p);       int mid = (l + r) >> 1;       if (ql <= mid) query((p << 1), l, mid, ql, qr, q);       if (qr > mid) query(((p << 1) | 1), mid + 1, r, ql, qr, q);       return;     }   } T;   vector<int> prime;   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) bas.set(i);     for (int i = 2; i < m; i++) prm.set(i);     for (int i = 2; i < m; i++) {       if (prm[i]) prime.push_back(i);       for (int j = 0; j < prime.size() && i * prime[j] < m; j++) {         prm[i * prime[j]] = 0;         if ((i % prime[j]) == 0) break;       }     }     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), a[i] %= m;     for (int i = 1, ti, tj; i < n; i++) {       scanf( %d%d , &ti, &tj);       v[ti].push_back(tj);       v[tj].push_back(ti);     }     dfs(1, 0);     T.build(1, 1, n);     scanf( %d , &Q);     bitset<1000> ans;     while (Q--) {       int opt, x, y;       scanf( %d%d , &opt, &x);       if (opt == 1) {         scanf( %d , &y);         y %= m;         T.modify(1, 1, n, dfn[x], dfn[x] + siz[x] - 1, y);       } else {         ans.reset();         T.query(1, 1, n, dfn[x], dfn[x] + siz[x] - 1, ans);         printf( %d n , (ans & prm).count());       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct ppp {     int x1, x2, y1, y2;     void make_pair(int x1_, int x2_, int y1_, int y2_) {       x1 = x1_;       x2 = x2_;       y1 = y1_;       y2 = y2_;     }   } a[120];   long long ans;   int n, m, i, j, k, x, y, l, r, P[220], tot, Pn, u, d;   char c[1010][1010];   int Find(int x) { return lower_bound(P + 1, P + Pn + 1, x) - P; }   int main() {     scanf( %d%d%*d , &n, &m);     for (i = 1; i <= n; ++i) scanf( %s , c[i] + 1);     for (i = 1; i <= n; ++i)       for (j = 1; j <= m; ++j)         if (c[i][j] ==  * ) {           k = j;           while (c[i][k] ==  * ) k++;           k--;           l = i;           while (c[l][j] ==  * ) l++;           l--;           for (x = i; x <= l; ++x)             for (y = j; y <= k; ++y) c[x][y] =  . ;           a[++tot].make_pair(i, l, j, k);           P[++Pn] = i;           P[++Pn] = l;         }     P[++Pn] = 0;     P[++Pn] = n + 1;     sort(P + 1, P + Pn + 1);     Pn = unique(P + 1, P + Pn + 1) - P - 1;     for (i = 1; i <= tot; ++i) a[i].x1 = Find(a[i].x1), a[i].x2 = Find(a[i].x2);     for (u = 2; u < Pn; ++u) {       for (d = u; d < Pn; ++d) {         long long tmp = 0;         vector<pair<int, int> > Q;         for (i = 1; i <= tot; ++i) {           if (a[i].x2 < u || a[i].x1 > d) continue;           if (a[i].x1 >= u && a[i].x2 <= d)             Q.push_back(make_pair(a[i].y1, -1)),                 Q.push_back(make_pair(a[i].y2, 1));           else             Q.push_back(make_pair(a[i].y1, -100)),                 Q.push_back(make_pair(a[i].y2, 100));         }         sort(Q.begin(), Q.end());         int num = Q.size(), C, suml, sumr, cc;         Q.push_back(make_pair(m + 1, 0));         for (int C = 1; C <= 3; ++C) {           suml = sumr = 0;           cc = 0;           for (l = 0, r = 0; r < num; ++r) {             sumr += Q[r].second;             cc += max(0, Q[r].second);             if (!sumr) {               while (suml || cc > C) {                 suml -= Q[l].second;                 cc -= max(0, Q[l].second);                 l++;               }               if (!suml && cc == C)                 tmp += (Q[r + 1].first - Q[r].first) *                        (Q[l].first - (!l ? 0 : Q[l - 1].first));             }           }         }         ans += tmp * (P[u] - P[u - 1]) * (P[d + 1] - P[d]);       }     }     printf( %I64d n , ans);   }
#include <bits/stdc++.h>   int n, k, s, e, m, ans, temp, tp, tv;   bool m11, m22, first, b[100005], move;   char a[100005];   int dist() {     if (m - s < e - m)       return e - m;     else       return m - s;   }   int main() {     scanf( %d %d , &n, &k);     scanf( %s , a);     for (e = 0; e < n; e++) {       if (a[e] ==  0 ) temp++;       if (a[e] ==  0  && !first) s = e, first = true;       if (temp >= k + 1) break;     }     m = s;     ans = dist();     while (e < n) {       tv = dist();       tp = m;       move = false;       if (ans > dist()) {         ans = dist();       }       while (m <= e) {         m++;         if (a[m] ==  0 ) {           if (tv > dist()) {             tv = dist();             tp = m;             if (ans > dist()) {               ans = dist();             }           } else {             m = tp;             break;           }         }       }       while (e < n) {         e++;         if (e < n && a[e] ==  0 ) {           while (true) {             s++;             if (a[s] ==  0 ) {               if (m < s) {                 m = s;               }               move = true;               break;             }           }         }         if (move) break;       }     }     printf( %d n , ans);     return 0;   }