malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   double sqrDist(double x1, double y1, double x2, double y2) {     return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);   }   double dist(double x1, double y1, double x2, double y2) {     return sqrt(sqrDist(x1, y1, x2, y2));   }   const double PI = acos(-1.0);   int main() {     int x0, y0, v, t;     scanf( %d%d%d%d , &x0, &y0, &v, &t);     double r0 = 1.0 * v * t;     int n;     scanf( %d , &n);     vector<pair<double, int> > a;     for (int i = 0; i < n; i++) {       int x, y, r;       scanf( %d%d%d , &x, &y, &r);       double d = sqrDist(x, y, x0, y0);       if (d < 1.0 * r * r + eps) {         printf( %.11f , 1.0);         return 0;       }       d = sqrt(d);       if (r + r0 < d - eps) {         continue;       }       double angL, angR, ang;       double angM = atan2(y - y0, x - x0);       if (angM < 0) {         angM += 2 * PI;       }       double tLen = sqrt(d * d - 1.0 * r * r);       if (tLen < r0 + eps) {         ang = asin(r / d);       } else {         ang = acos((d * d + r0 * r0 - 1.0 * r * r) / (2 * d * r0));       }       angL = angM - ang;       angR = angM + ang;       if (angL < 0) {         a.push_back(make_pair(angL + 2 * PI, 1));         a.push_back(make_pair(2 * PI, -1));         a.push_back(make_pair(0.0, 1));         a.push_back(make_pair(angR, -1));       } else if (angR > 2 * PI) {         a.push_back(make_pair(angL, 1));         a.push_back(make_pair(2 * PI, -1));         a.push_back(make_pair(0.0, 1));         a.push_back(make_pair(angR - 2 * PI, -1));       } else {         a.push_back(make_pair(angL, 1));         a.push_back(make_pair(angR, -1));       }     }     sort(a.begin(), a.end());     double last = 0;     int c = 0;     double ans = 0;     for (auto& p : a) {       if (c > 0) {         ans += p.first - last;       }       c += p.second;       last = p.first;     }     ans /= 2 * PI;     printf( %.11f , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> r1, r2;   vector<bool> pd;   vector<int> out;   vector<pair<int, int>> mp;   int le(int i, int cur) {     if (cur == mp[i].first) return mp[i].second;     return mp[i].first;   }   bool mak(int i, int p) {     if (mp[i].first == -1)       mp[i].first = p;     else if (mp[i].second == -1)       mp[i].second = p;     else       return true;     return false;   }   class proc {     struct Dt {       int pos;       bool fl;     };     int p;     int c;     vector<Dt> out_c;       public:     proc(int i) {       p = i;       c = 0;       re();       if (c > out_c.size() / 2) {         for (auto& i : out_c)           if (!i.fl) out.push_back(i.pos);       } else         for (auto& i : out_c)           if (i.fl) out.push_back(i.pos);     }       private:     void re() {       if (pd[p]) return;       pd[p] = 1;       if (r1[p] == r2[p]) return;       int x = le(r1[p], p);       if (r1[p] == r1[x]) {         ++c;         swap(r1[x], r2[x]);         out_c.push_back({x, 1});       } else         out_c.push_back({x, 0});       p = x;       re();     }   };   int main() {     ios_base::sync_with_stdio(false);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       r1.resize(n);       r2.resize(n);       mp = vector<pair<int, int>>(n, {-1, -1});       pd = vector<bool>(n, 0);       out = vector<int>(0);       for (int i = 0; i < n; ++i) {         cin >> r1[i];         --r1[i];       }       for (int i = 0; i < n; ++i) {         cin >> r2[i];         --r2[i];       }       for (int i = 0; i < n; ++i)         if (mak(r1[i], i) || mak(r2[i], i)) goto badcase;       for (int i = 0; i < n; ++i) proc lp(i);       cout << out.size() << endl;       for (auto i : out) cout << i + 1 <<    ;       cout << endl;       continue;     badcase:       cout << -1 << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> readvec(long long length, long long off = 0);   template <typename T>   string ts(T v);   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n;     long long z;     cin >> n >> z;     vector<long long> v = readvec(n);     sort(v.begin(), v.end());     long long left = 0;     long long right = v.size() / 2;     long long ans = 0;     while (true) {       if (left >= v.size() / 2 || right >= v.size()) break;       if (v[right] - v[left] >= z) {         ans++;         left++;         right++;       } else {         right++;       }     }     cout << ans << endl;   }   template <typename T>   string ts(T v) {     stringstream ss;     ss <<  [ ;     for (auto it = v.begin(); it != v.end(); it++) {       if (it != v.begin()) ss <<  ,  ;       ss << *it;     }     ss <<  ] ;     return ss.str();   }   vector<long long> readvec(long long length, long long off) {     vector<long long> v;     for (long long i = 0; i < length; i++) {       long long x;       cin >> x;       v.push_back(x + off);     }     return v;   }
#include <bits/stdc++.h>   using namespace std;   int arr[2505][2505], sum[2505][2505], n, m;   int get_sum(int x1, int y1, int x2, int y2) {     x2 = min(x2, n);     y2 = min(y2, m);     assert(x1 <= x2);     assert(y1 <= y2);     return sum[x2][y2] - sum[x2][y1 - 1] - sum[x1 - 1][y2] + sum[x1 - 1][y1 - 1];   }   int main() {     ios::sync_with_stdio(false);     ;     cin.tie(0);     ;     int i, j, k, ans = 100000000, ones, zeroes;     string s;     cin >> n >> m;     for (i = 1; i <= n; i++) {       cin >> s;       s =     + s;       for (j = 1; j <= m; j++) arr[i][j] = s[j] -  0 ;     }     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++)         sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + arr[i][j];     }     for (k = 2; k <= max(n, m); k++) {       int got = 0;       for (i = 1; i <= n; i = i + k) {         for (j = 1; j <= m; j = j + k) {           ones = get_sum(i, j, i + k - 1, j + k - 1);           zeroes = k * k - ones;           got += min(ones, zeroes);         }       }       ans = min(ans, got);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   int main() {     int n;     string s, ss;     cin >> s >> n;     vector<pair<int, string> > v(n + 1);     v[0] = make_pair(0, s);     char next;     while (cin.get(next))       if (next ==   n ) break;     for (int i = 1; i <= n; ++i) {       getline(cin, ss);       if (ss.length() > 3)         v[i] = make_pair(ss[0] -  0 , ss.substr(3));       else         v[i] = make_pair(ss[0] -  0 ,   );     }     long long val[10], len[10];     for (int i = 0; i < 10; ++i) val[i] = i, len[i] = 10;     for (int i = n; i >= 0; --i) {       int cu = v[i].first;       string s = v[i].second;       if (s.empty()) {         val[cu] = 0;         len[cu] = 1;         continue;       }       long long pow = 1;       long long va = 0;       for (int j = s.length() - 1; j >= 0; --j) {         va += ((val[(s[j] -  0 )]) * pow) % MOD;         va %= MOD;         pow = (pow * len[(s[j] -  0 )]) % MOD;       }       len[cu] = pow;       val[cu] = va;     }     cout << val[0] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = (int)2e5 + 5;   int n, a[maxn], vis[2 * maxn], mx[maxn];   long long ans;   vector<int> slist[maxn];   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   void doit(int d) {     for (int i = 0; i < d; i++) mx[i] = 0;     for (int i = 0; i < n; i++) vis[i] = 0;     for (int i = 0; i < n; i++) mx[i % d] = max(mx[i % d], a[i]);     for (int i = 0; i < n; i++)       if (a[i] == mx[i % d]) vis[i] = 1;     for (int i = n; i < 2 * n; i++) vis[i] = vis[i - n];     int lst = -1;     for (int i = 2 * n - 1; i >= 0; i--) {       if (vis[i] && lst == -1)         lst = i;       else if (!vis[i])         lst = -1;       if (lst == -1 || i >= n) continue;       int len = lst - i + 1;       int idx =           upper_bound(slist[d].begin(), slist[d].end(), len) - slist[d].begin();       ans += idx;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.clear();     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 1; i < n; i++) slist[gcd(i, n)].push_back(i);     for (int i = 1; i * i <= n; i++) {       if (n % i) continue;       doit(i);       if (n / i != i) doit(n / i);     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> G[200005];   bool V[200006] = {0};   int S[200006] = {0};   int n;   long long d = 0, mx = 0;   void dfs(int p) {     V[p] = 1;     d++;     int u = 0;     for (int i = 0; i < G[p].size(); i++) {       int cp = G[p][i];       if (!V[cp]) {         dfs(cp);         u++;       }     }     if (!u) mx = max(mx, d);     d--;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       S[i] = x;       if (x == -1) continue;       G[x].push_back(i);       G[i].push_back(x);     }     for (int i = 1; i <= n; i++) {       if (!V[i] && S[i] == -1) {         d = 0;         dfs(i);       }     }     cout << mx;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int a[1000000];   struct cr {     int l;     int r;     int d;   } op[1000000];   long long int kt[1000000];   long long int ktt[1000000];   long long int fiop[1000000];   long long int vp[1000000];   long long int vpp[1000000];   long long int mba[1000000];   int main() {     int n, m, k, b, c, i, j;     long long int uv;     cin >> n >> m >> k;     for (i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     for (i = 1; i <= m; i++) {       cin >> op[i].l >> op[i].r >> op[i].d;     }     for (i = 0; i < k; i++) {       cin >> b >> c;       kt[b]++;       ktt[c]--;     }     b = 0;     for (i = 1; i <= m; i++) {       b += kt[i];       fiop[i] += b;       b += ktt[i];     }     uv = 0;     for (i = 1; i <= m; i++) {       uv = (op[i].d * fiop[i]);       vp[op[i].l] += uv;       vpp[op[i].r] -= uv;     }     uv = 0;     for (i = 0; i <= 100010; i++) {       uv += vp[i];       mba[i] += uv;       uv += vpp[i];     }     for (i = 1; i <= n; i++) {       a[i] += mba[i];       cout << a[i] <<    ;     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using vi = vector<int>;   using db = double;   const int mxn = 100006;   int n, m;   int a[mxn];   vi e[mxn];   bool v[mxn];   vi V;   void dfsv(int x, int p) {     v[x] = true;     V.push_back(x);     for (auto i : e[x])       if (i != p && !v[i]) dfsv(i, x);   }   bool v1[mxn];   void dfs1(int x, int p) {     v1[x] = true;     for (auto i : e[x])       if (i != p)         if (v1[i])           throw i;         else           dfs1(i, x);   }   bool v2[mxn];   bool dfs2(int x, int p, int o) {     v2[x] = true;     for (auto i : e[x])       if (i != p)         if (i == o) {           a[x] = 1;           return true;         } else if (!v2[i]) {           if (dfs2(i, x, o)) {             a[x] = 1;             return true;           }         }     return false;   }   vector<vi> c;   void dfs3(int x, int p) {     c.back().push_back(x);     for (auto i : e[x])       if (i != p) dfs3(i, x);   }   void solve(int x) {     V = {};     dfsv(x, 0);     int o = 0;     try {       dfs1(x, 0);     } catch (int x) {       o = x;     }     if (o) {       dfs2(o, 0, o);     } else {       int leaf = 0;       for (auto i : V)         if (e[i].size() == 1) ++leaf;       if (leaf <= 2) return;       if (leaf >= 4) {         for (auto i : V)           if (e[i].size() == 1)             a[i] = 1;           else             a[i] = 2;       } else {         int r = 0;         for (auto i : V)           if (e[i].size() == 3) r = i;         assert(r);         c = {};         for (auto i : e[r]) {           c.push_back({r});           dfs3(i, r);         }         vi k;         for (auto i : c) k.push_back(min(6, (int)i.size()));         if (k[0] * k[1] + k[0] * k[2] + k[1] * k[2] <= k[0] * k[1] * k[2]) {           const int s = 60;           a[r] = s;           for (int i = 0; i < 3; ++i)             for (int j = 0; j < k[i]; ++j) a[c[i][j]] = s / k[i] * (k[i] - j);         }       }     }   }   int main() {     int t;     cin >> t;     while (t--) {       scanf( %d%d , &n, &m);       for (int i = 1; i <= n; ++i) e[i] = {};       for (int i = 0; i < m; ++i) {         int x, y;         scanf( %d%d , &x, &y);         e[x].push_back(y);         e[y].push_back(x);       }       fill(v, v + n + 1, false);       fill(v1, v1 + n + 1, false);       fill(v2, v2 + n + 1, false);       fill(a, a + n + 1, 0);       for (int i = 1; i <= n; ++i)         if (!v[i]) solve(i);       if (count(a + 1, a + n + 1, 0) == n) {         puts( NO );       } else {         puts( YES );         for (int i = 1; i <= n; ++i) printf( %d  , a[i]);         puts(  );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string rat[100], cw[100], man[100], c;     int a = 0, b = 0, d = 0;     for (int i = 0; i < n; i++) {       string name, s;       cin >> name >> s;       if (s ==  captain )         c = name;       else if (s ==  woman  || s ==  child ) {         cw[a] = name;         a++;       } else if (s ==  rat ) {         rat[b] = name;         b++;       } else if (s ==  man ) {         man[d] = name;         d++;       } else if (s ==  captain )         c = name;     }     for (int i = 0; i <= b; i++) {       if (i == b)         cout << rat[i];       else         cout << rat[i] << endl;     }     for (int i = 0; i <= a; i++) {       if (i == a)         cout << cw[i];       else         cout << cw[i] << endl;     }     for (int i = 0; i <= d; i++) {       if (i == d)         cout << man[i];       else         cout << man[i] << endl;     }     cout << c << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k;   int p[2010] = {0};   int cnt = 0;   int sum[2010];   int dp[2010];   int a[200010];   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     sort(a + 1, a + n + 1);     n = min(n, k);     for (int i = 1, x, y; i <= m; ++i) {       scanf( %d%d , &x, &y);       if (x > k) continue;       p[x] = max(p[x], y);     }     sum[0] = 0;     for (int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + a[i];     memset(dp, 0x3f3f3f3f, sizeof dp);     dp[0] = 0;     for (int i = 1; i <= k; ++i) {       for (int j = 0; j < i; ++j) {         dp[i] = min(dp[i], dp[j] + sum[i] - sum[j + p[i - j]]);       }     }     printf( %d n , dp[k]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, min = INT_MAX, count = 0;     int arr[1000001];     int j;     cin >> n;     for (j = 0; j < n; j++) cin >> arr[j];     sort(arr, arr + n);     int i, diff;     for (i = 0; i < n - 1; i++) {       j = i + 1;       diff = arr[j] - arr[i];       if (diff < 0) diff = -diff;       if (diff < min) {         min = diff;         count = 1;       } else if (diff == min)         count++;     }     cout << min <<     << count;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   using namespace std;   int num[1001];   long long n;   long long check(long long k) {     long long p = 0, v = 0;     long long t = n;     while (t) {       if (t >= k) {         p += k;         t -= k;       } else {         p += t;         t = 0;       }       v += t / 10;       t -= t / 10;     }     if (v <= p)       return 1;     else       return 0;   }   int main() {     cin >> n;     long long l = 1;     long long r = 1e18;     long long ans = 0;     while (l <= r) {       long long mid = (l + r) / 2;       if (check(mid)) {         ans = mid;         r = mid - 1;       } else {         l = mid + 1;       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   const int mod = 1e9 + 7;   int n, m, d, k, x, ans, pos[N], a[30];   bool f[1 << 20];   int cal(int x) {     int res = 0;     for (int i = (0); i < (m); i++)       if (x & (1 << i)) res++;     return res;   }   int main() {     scanf( %d%d%d , &n, &m, &d);     for (int i = (0); i < (m); i++) {       scanf( %d , &k);       for (int j = (0); j < (k); j++) {         scanf( %d , &x);         pos[x] = i;       }     }     for (int i = (1); i < (d + 1); i++) a[pos[i]]++;     for (int i = (d); i < (n + 1); i++) {       if (i > d) a[pos[i]]++, a[pos[i - d]]--;       ;       x = 0;       for (int j = (0); j < (m); j++)         if (!a[j]) x += (1 << j);       f[x] = 1;     }     ans = m;     for (int i = (1 << m) - 1; i >= 1; i--) {       if (f[i]) {         for (int j = (0); j < (m); j++)           if ((1 << j) & i) {             f[i - (1 << j)] = 1;           }       } else         ans = min(ans, cal(i));     }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   const int MOD = 1e9 + 7;   int add(int a, int b) { return a + b >= MOD ? a + b - MOD : a + b; }   int mul(int a, int b) { return 1ll * a * b % MOD; }   int n, x[N], y[N];   vector<int> g[N];   map<int, int> px, py;   int far[N], cnt, cir;   void dfs(int u, int fa) {     if (!px.count(x[u])) cnt++;     px[x[u]] = u;     if (!py.count(y[u])) cnt++;     py[y[u]] = u;     for (auto v : g[u]) {       if (v == fa) continue;       if (~far[v]) {         cir = 1;         continue;       }       far[v] = u;       dfs(v, u);     }   }   int pw2[N * 2];   void solve() {     for (int i = (0); i < (n); ++i) g[i].clear();     px.clear();     py.clear();     for (int i = (0); i < (n); ++i) {       int &x = ::x[i], &y = ::y[i];       scanf( %d%d , &x, &y);       if (px.count(x)) {         int j = px[x];         g[i].push_back(j);         g[j].push_back(i);       }       px[x] = i;       if (py.count(y)) {         int j = py[y];         g[i].push_back(j);         g[j].push_back(i);       }       py[y] = i;     }     int ans = 1;     fill_n(far, n, -1);     pw2[0] = 1;     for (int i = (1); i < (2 * n + 1); ++i) pw2[i] = add(pw2[i - 1], pw2[i - 1]);     for (int i = (0); i < (n); ++i)       if (!~far[i]) {         px.clear();         py.clear();         far[i] = cnt = cir = 0;         dfs(i, -1);         ans = mul(ans, pw2[cnt] - !cir);       }     printf( %d n , ans);   }   int main() {     while (~scanf( %d , &n)) solve();     return 0;   }
#include <bits/stdc++.h>   int a, b, yue[100000], l[10100], h[10100], p[10100], ans[10100], gs, c, n;   void qsort(int x, int y) {     int i, j, t, mid;     i = x;     j = y;     mid = yue[(i + j) / 2];     do {       while (yue[i] < mid) i++;       while (yue[j] > mid) j--;       if (i <= j) {         t = yue[i];         yue[i] = yue[j];         yue[j] = t;         i++;         j--;       }     } while (i <= j);     if (i < y) qsort(i, y);     if (x < j) qsort(x, j);   }   void qsort1(int x, int y) {     int i, j, t, mid;     i = x;     j = y;     mid = h[(i + j) / 2];     do {       while (h[i] > mid) i++;       while (h[j] < mid) j--;       if (i <= j) {         t = h[i];         h[i] = h[j];         h[j] = t;         t = l[i];         l[i] = l[j];         l[j] = t;         t = p[i];         p[i] = p[j];         p[j] = t;         i++;         j--;       }     } while (i <= j);     if (i < y) qsort1(i, y);     if (x < j) qsort1(x, j);   }   int gcd(int a, int b) {     if (a > b) {       int t;       t = a;       a = b;       b = t;     }     if (a == 0)       return b;     else       return gcd(b % a, a);   }   int main() {     int i, j;     while (scanf( %d %d , &a, &b) != EOF) {       c = gcd(a, b);       for (i = 1; i * i <= c; i++)         if (c % i == 0) {           gs++;           yue[gs] = i;           gs++;           yue[gs] = c / i;         }       qsort(1, gs);       scanf( %d , &n);       for (i = 0; i < n; i++) {         p[i] = i;         scanf( %d %d , &l[i], &h[i]);       }       qsort1(0, n - 1);       j = gs;       for (i = 0; i < n; i++) {         while (yue[j] > h[i]) j--;         if (yue[j] < l[i])           ans[p[i]] = -1;         else           ans[p[i]] = yue[j];       }       for (i = 0; i < n; i++) printf( %d n , ans[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       string s;       cin >> s;       map<char, int> mp;       for (auto it : s) {         mp[it]++;       }       int ans = 1;       for (int i = 1; i * i <= k; i++) {         if (k % i == 0) {           int fact1 = i, fact2 = k / i;           for (int j = fact1; j <= n; j += fact1) {             int x = 0;             for (auto it : mp) x += (it.second / (j / fact1));             if (x >= fact1) ans = max(ans, j);           }           for (int j = fact2; j <= n; j += fact2) {             int x = 0;             for (auto it : mp) x += (it.second / (j / fact2));             if (x >= fact2) ans = max(ans, j);           }         }       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long nxt[45][3], lnk[45], pre[45][3];   string s;   long long n;   pair<long long, long long> sh[45][45][2];   long long dp[41][41][41][41][2];   long long sol(long long i, long long pre, long long l, long long r,                 long long f = 0) {     if (pre == s.size()) f = 1;     if (r - l + 1 == s.size()) f = 1;     if (i == n) {       if (f) return 1;       string final;       if (pre) final = s.substr(0, pre);       if (r - l + 1) final += s.substr(l, r - l + 1);       if (final.find(s) != string::npos) {         return 1;       }       return 0;     }     if (~dp[i][pre][l][r][f]) return dp[i][pre][l][r][f];     if (r - l + 1 == i)       dp[i][pre][l][r][f] =           sol(i + 1, nxt[pre][0], sh[l][r][0].first, sh[l][r][0].second, f) +           sol(i + 1, nxt[pre][1], sh[l][r][1].first, sh[l][r][1].second, f);     else       dp[i][pre][l][r][f] =           sol(i + 1, nxt[pre][0], l, r, f) + sol(i + 1, nxt[pre][1], l, r, f);     return dp[i][pre][l][r][f];   }   void solve() {     cin >> n;     cin >> s;     for (long long i = 0; i < s.size(); i++) {       if (i > 1) {         lnk[i] = nxt[lnk[i - 1]][s[i - 1] -  0 ];       }       for (long long j = 0; j < 2; j++) {         if (s[i] == j +  0 )           nxt[i][j] = i + 1;         else if (i > 0) {           nxt[i][j] = nxt[lnk[i]][j];         }       }     }     for (long long i = 0; i < s.size(); i++) {       for (long long j = 0; j < s.size(); j++) {         for (long long k = 0; k < 2; k++) {           string pt;           if (j >= i) pt += s.substr(i, j - i + 1);           pt.push_back(k +  0 );           long long x = s.find(pt);           if (x != string::npos)             sh[i][j][k] = {x, x + j - i + 1};           else             sh[i][j][k] = {i, j};         }       }     }     if (s.size() == 1) {       long long x = s.back() -  0 ;       sh[1][0][x] = {0, 0};       sh[1][0][!x] = {1, 0};     }     memset(dp, -1, sizeof dp);     cout << sol(0, 0, 1, 0, 0) << endl;   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[1010];   int main() {     int n, m;     cin >> n >> m;     int tmp;     int ans = 0;     memset(a, 0, sizeof(a));     for (int i = 1; i <= m; i++) {       cin >> tmp;       a[tmp]++;       int b = 1;       for (int i = 1; i <= n; i++)         if (!a[i]) b = 0;       if (b) {         ans++;         for (int i = 1; i <= m; i++) a[i]--;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n, q, x, y, cnt = 0;     cin >> n >> q;     vector<vector<long long int>> dp(3, vector<long long int>(n + 2, 0));     while (q--) {       cin >> x >> y;       if (dp[x][y] == 0) {         cnt += (dp[3 - x][y] == 1);         cnt += (dp[3 - x][y - 1] == 1);         cnt += (dp[3 - x][y + 1] == 1);         dp[x][y] = 1;       } else {         cnt -= (dp[3 - x][y] == 1);         cnt -= (dp[3 - x][y - 1] == 1);         cnt -= (dp[3 - x][y + 1] == 1);         dp[x][y] = 0;       }       if (cnt == 0)         cout <<  Yes  <<   n ;       else         cout <<  No  <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     long long int t = 1;     while (t--) {       solve();     }     return 0;   }