malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = (1 << 11);   const int maxs = 27;   string s[maxn];   vector<int> NextIn[maxn][maxs];   int NextOut[maxn][maxs], First[maxn][maxs], a[maxn];   pair<int, int> dp[maxn][maxn];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     memset(First, 63, sizeof First);     memset(NextOut, 63, sizeof NextOut);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> s[i];       int m = s[i].size();       for (int ch = 0; ch < maxs; ch++) NextIn[i][ch].resize(m);       for (int j = m - 1; j >= 0; j--)         for (int ch = 0; ch < maxs; ch++) {           if (j + 1 < m && s[i][j + 1] == ch +  a )             NextIn[i][ch][j] = j + 1;           else if (j + 1 < m)             NextIn[i][ch][j] = NextIn[i][ch][j + 1];           else             NextIn[i][ch][j] = 1e9;         }       for (int j = m - 1; j >= 0; j--) First[i][s[i][j] -  a ] = j;     }     int m;     cin >> m;     for (int i = 0; i < m; i++) cin >> a[i], a[i]--;     for (int i = m - 1; i >= 0; i--)       for (int ch = 0; ch < maxs; ch++) {         if (i + 1 < m && First[a[i + 1]][ch] < 1e7)           NextOut[i][ch] = i + 1;         else           NextOut[i][ch] = NextOut[i + 1][ch];       }     string t;     cin >> t;     int k = t.size();     for (int i = 0; i < maxn; i++)       for (int j = 0; j < maxn; j++) dp[i][j] = {1e9, 1e9};     dp[0][0] = {0, -1};     for (int i = 1; i <= k; i++)       for (int j = 0; j <= k; j++) {         int ch = t[i - 1] -  a ;         dp[i][j] = dp[i - 1][j];         if (!j) continue;         auto tmp = dp[i - 1][j - 1];         if (tmp.first >= m) continue;         int ind = a[tmp.first];         if (tmp.second == -1 && First[ind][ch] < 1e7)           dp[i][j] = min(dp[i][j], make_pair(tmp.first, First[ind][ch]));         else if (tmp.second != -1 && NextIn[ind][ch][tmp.second] < 1e7)           dp[i][j] =               min(dp[i][j], make_pair(tmp.first, NextIn[ind][ch][tmp.second]));         if (NextOut[tmp.first][ch] < m) {           int pt = NextOut[tmp.first][ch];           dp[i][j] = min(dp[i][j], make_pair(pt, First[a[pt]][ch]));         }       }     int ans = 0;     while (ans + 1 <= k && dp[k][ans + 1].first < m) ans++;     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long int n, I;   vector<long long int> vec;   vector<long long int> comp;   long long int K;   int main() {     scanf( %lld %lld , &n, &I);     for (int i = 1; i <= n; i++) {       long long int a;       scanf( %lld , &a);       vec.push_back(a);     }     K = 1 << min((long long int)20, 8 * I / n);     sort(vec.begin(), vec.end());     long long int pre = -1;     for (int i = 1; i <= n; i++) {       if (vec[i - 1] != pre) {         comp.push_back(i);         pre = vec[i - 1];       }     }     if (8 * I / n >= 20) {       printf( 0 );       return 0;     }     int ans = 1000000000;     for (int i = 0; i < comp.size(); ++i) {       int num = comp[i] - 1 + (i + K < comp.size() ? n + 1 - comp[i + K] : 0);       ans = min(num, ans);     }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const int inf = 0x3f3f3f3f;   const double eps = 1e-15;   const long long INF = (1LL << 60);   int cnt[1010];   int a[1010];   int M[1010];   int m;   int dp[1010][1010][2];   int main() {     int n, m, x;     scanf( %d%d , &n, &m);     memset(dp, 0, sizeof(dp));     memset(cnt, 0, sizeof(cnt));     for (int i = 1; i <= n; ++i) {       scanf( %d , &x);       x %= m;       ++cnt[x];     }     if (n > m) {       printf( YES n );       return 0;     }     dp[0][0][0] = 1;     for (int i = 0; i < m; ++i) {       for (int j = 0; j < m; ++j) {         if (dp[i][j][0]) {           dp[i + 1][j][0] = 1;         }         if (dp[i][j][1]) {           dp[i + 1][j][1] = 1;         }         for (int k = 1; k <= cnt[i]; ++k) {           if (dp[i][j][0] || dp[i][j][1]) {             dp[i + 1][(j + k * i) % m][1] = 1;           }         }       }     }     bool flag = dp[m][0][1];     puts(flag ?  YES  :  NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());   const int N = 200005;   const int M = 1000000007;   long long ast(long long x, long long n) {     x %= M;     long long ans = 1;     while (n) {       if (n % 2 == 1) ans = (ans * x) % M;       x = (x * x) % M;       n /= 2;     }     return ans;   }   int n;   long long a[N];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %lld , &a[i]);     long long u = 2;     long long k = 1;     for (int i = 1; i <= n; ++i) {       u = ast(u, a[i]);       if (a[i] % 2 == 0) k = 0;     }     u = (u * ast(2, M - 2)) % M;     long long x;     if (k == 0)       x = ((u + 1) * ast(3, M - 2)) % M;     else       x = ((u - 1 + M) % M * ast(3, M - 2)) % M;     printf( %lld/%lld n , x, u);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, st[350005], dr[350005], grad[350005], bad[350005], l, order[350005],       len;   bool used[350005], stare[350005];   vector<int> L[350005];   vector<int>::iterator it[350005];   inline void add_edge(int x, int y) {     ++m;     L[x].push_back(m);     L[y].push_back(m);     st[m] = x;     dr[m] = y;   }   inline void Dfs(int nod) {     while (it[nod] != L[nod].end()) {       if (used[*it[nod]]) {         ++it[nod];         continue;       }       used[*it[nod]] = 1;       Dfs(st[*it[nod]] + dr[*it[nod]] - nod);     }     order[++len] = nod;   }   int main() {     int i, j, x, y;     cin >> n >> m;     for (i = 1; i <= m; ++i) {       cin >> st[i] >> dr[i];       L[st[i]].push_back(i);       L[dr[i]].push_back(i);       ++grad[st[i]];       ++grad[dr[i]];     }     for (i = 1; i <= n; ++i)       if (grad[i] & 1) bad[++l] = i;     for (i = 1; i < l; i += 2) add_edge(bad[i], bad[i + 1]);     if (m & 1) add_edge(1, 1);     for (i = 1; i <= n; ++i) it[i] = L[i].begin();     Dfs(1);     cout << m <<   n ;     for (i = 1; i < len; ++i) {       x = order[i];       y = order[i + 1];       if (!stare[x]) {         cout << y <<     << x <<   n ;         stare[y] = 1;       } else {         cout << x <<     << y <<   n ;         stare[y] = 0;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int R, C;     cin >> R >> C;     char m[R][C];     for (int i = 0; i < R; i++)       for (int j = 0; j < C; j++) cin >> m[i][j];     for (int i = 0; i < R; i++)       for (int j = 0; j < C; j++) {         if (m[i][j] ==  S ) {           if (i > 0)             if (m[i - 1][j] ==  W ) {               cout <<  No n ;               return 0;             }           if (i < R - 1)             if (m[i + 1][j] ==  W ) {               cout <<  No n ;               return 0;             }           if (j > 0)             if (m[i][j - 1] ==  W ) {               cout <<  No n ;               return 0;             }           if (j < C - 1)             if (m[i][j + 1] ==  W ) {               cout <<  No n ;               return 0;             }         }       }     cout <<  Yes n ;     for (int i = 0; i < R; i++)       for (int j = 0; j < C; j++)         if (m[i][j] ==  . ) m[i][j] =  D ;     for (int i = 0; i < R; i++) {       for (int j = 0; j < C; j++) {         cout << m[i][j];       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m;   long long arr[200002], time_freq[101];   void solve() {     long long total_time = 0;     for (long long i = 0; i < n; i++) {       long long exam_start_time = total_time + arr[i] - m;       int student_removed = 0;       if (exam_start_time > 0) {         for (int j = 100; j > 0; j--) {           long long y = time_freq[j] * j;           if (exam_start_time <= y) {             student_removed += ((exam_start_time + j - 1) / j);             break;           }           exam_start_time -= (time_freq[j] * j);           student_removed += time_freq[j];         }       }       total_time += arr[i];       time_freq[arr[i]]++;       cout << student_removed <<    ;     }     cout << endl;   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> arr[i];     ;     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   map<int, int> mp;   int main() {     std::ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int n, k, tmp = 1, mx = 0;     cin >> n >> k;     while (tmp <= k + 1) {       int pos, x;       cout <<  ?  <<    ;       for (int i = 1; i <= k + 1; i++) {         if (i != tmp) cout << i <<    ;       }       cout << endl;       cout.flush();       tmp++;       cin >> pos >> x;       mp[x]++;       mx = max(mx, x);     }     cout <<  !  <<     << mp[mx] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int k[3];     while (cin >> k[0] >> k[1] >> k[2]) {       bool flag = false;       int one = 0, two = 0, three = 0, four = 0;       for (int i = 0; i < 3; i++) {         if (k[i] == 1) one++;         if (k[i] == 2) two++;         if (k[i] == 3) three++;         if (k[i] == 4) four++;       }       if (one >= 1 || two >= 2 || three == 3 || two == 1 && four == 2)         flag = true;       if (flag)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   pair<int, int> tc[30];   bool dp[5][110][505];   int vis[5][110][505], n, k, Trow[30], kase, stx, sty;   char mp[5][110];   bool solve(int x, int y, int mv) {     if (x < 1 || x > 3 || y < 1) return 0;     if (y > n) return 1;     bool oc1 = 0, oc2 = 0, oc3 = 0;     if (vis[x][y][mv] == kase) return dp[x][y][mv];     for (int i = 1; i <= k; i++) {       if (x == Trow[i]) {         if (y >= (tc[i].first - mv * 2) && y <= (tc[i].second - mv * 2)) return 0;         if (y + 1 >= (tc[i].first - mv * 2) && y + 1 <= (tc[i].second - mv * 2))           oc1 = 1;       } else if (x - Trow[i] == 1) {         if (y + 1 >= (tc[i].first - mv * 2) && y + 1 <= (tc[i].second - mv * 2))           oc2 = 1;       } else if (Trow[i] - x == 1) {         if (y + 1 >= (tc[i].first - mv * 2) && y + 1 <= (tc[i].second - mv * 2))           oc3 = 1;       }     }     bool op1 = 0, op2 = 0, op3 = 0;     if (!oc1) op1 = solve(x, y + 1, mv + 1);     if (!oc1 && !oc2) op2 = solve(x - 1, y + 1, mv + 1);     if (!oc1 && !oc3) op3 = solve(x + 1, y + 1, mv + 1);     vis[x][y][mv] = kase;     return dp[x][y][mv] = (op1 || op2 || op3);   }   int main() {     int ks;     scanf( %d , &ks);     for (kase = 1; kase <= ks; kase++) {       scanf( %d %d , &n, &k);       for (int i = 1; i <= 3; i++) scanf( %s , &mp[i][1]);       int cnt = 1;       for (int i = 1; i <= 3; i++) {         for (int j = 1; j <= n; j++) {           if (mp[i][j] ==  s )             stx = i, sty = j;           else if (mp[i][j] !=  . ) {             char S = mp[i][j];             int kk = j;             while (kk <= n && mp[i][kk] == S) mp[i][kk] =  . , kk++;             Trow[cnt] = i;             tc[cnt].first = j;             tc[cnt].second = kk - 1;             cnt++;           }         }       }       printf( %s n , solve(stx, sty, 0) ?  YES  :  NO );     }   }
#include <bits/stdc++.h>   #pragma GCC target( fma )   #pragma GCC optimize( unroll-loops,-Ofast )   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   long long a[500005];   int n;   set<long long> buck[1000];   long long c[1000];   void fix(int v) {     int l = v * 700;     int r = (v + 1) * 700;     r = min(r, n);     buck[v].clear();     for (int i = l; i < r; ++i) {       a[i] += c[v];       buck[v].insert(a[i]);     }     c[v] = 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int q;     cin >> n >> q;     for (int i = 0; i < n; i++) {       cin >> a[i];       buck[i / 700].insert(a[i]);     }     while (q--) {       int t, l, r, x;       cin >> t;       if (t == 1) {         cin >> l >> r >> x;         --l;         --r;         if (l / 700 == r / 700) {           for (int i = l; i <= r; i++) a[i] += x;           fix(r / 700);           continue;         }         if (l % 700 != 0) {           for (; l % 700 != 0; ++l) {             a[l] += x;           }           fix(l / 700 - 1);         }         l /= 700;         if (r % 700 != 700 - 1) {           for (; r % 700 != 700 - 1; --r) {             a[r] += x;           }           fix(r / 700 + 1);         }         r /= 700;         for (; l <= r; l++) c[l] += x;       } else {         cin >> x;         l = r = -1;         for (int i = 0; i <= n / 700; ++i) {           if (buck[i].count(x - c[i])) {             for (int j = i * 700; 1; ++j) {               if (a[j] == x - c[i]) {                 l = j;                 break;               }             }             break;           }         }         for (int i = n / 700; i >= 0; --i) {           if (buck[i].count(x - c[i])) {             for (int j = i * 700 + 700 - 1; 1; --j) {               if (a[j] == x - c[i]) {                 r = j;                 break;               }             }             break;           }         }         if (l == -1) {           cout << -1 <<   n ;         } else {           cout << r - l <<   n ;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (a % b == 0)       return b;     else       return gcd(b, a % b);   }   int main() {     int n, m, an[120], am[120], fa = -1, fb = -1, f = 0, a, b;     cin >> n >> m;     for (int i = 0; i < n + 1; i++) {       cin >> an[i];       if (f == 0 && an[i] != 0) {         f = 1;         fa = n - i;       }     }     f = 0;     for (int i = 0; i < m + 1; i++) {       cin >> am[i];       if (f == 0 && am[i] != 0) {         f = 1;         fb = m - i;       }     }     a = an[n - fa];     b = am[m - fb];     if (fa < 0 && fb < 0) {       cout <<  0/1  << endl;     }     if (fb == fa) {       f = gcd(a, b);       a /= f;       b /= f;       if (b < 0) {         b = abs(b);         a *= -1;       }       cout << a <<  /  << b << endl;     }     if (fa > fb) {       if (a * b > 0)         cout <<  Infinity  << endl;       else         cout <<  -Infinity  << endl;     } else if (fa < fb) {       cout <<  0/1  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp[100010];   int main() {     int val90, val1440, n;     cin >> n;     dp[0] = 0;     unsigned int ar[n + 10];     for (int i = 1; i <= n; i++) {       cin >> ar[i];     }     val1440 = val90 = 1;     for (int i = 1; i <= n; i++) {       while (ar[i] - ar[val1440] >= 1440) {         val1440++;       }       while (ar[i] - ar[val90] >= 90) {         val90++;       }       dp[i] = min(dp[i - 1] + 20, dp[val90 - 1] + 50);       dp[i] = min(dp[i], dp[val1440 - 1] + 120);       int ans = dp[i] - dp[i - 1];       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   const int maxlog = 24;   int par[maxn][maxlog], h[maxn];   int siz[maxn];   bool mark[maxn];   int n;   vector<int> adj[maxn];   void dfs(int x) {     mark[x] = 1;     for (int i = 0; i < adj[x].size(); i++) {       int child = adj[x][i];       if (!mark[child]) {         par[child][0] = x;         h[child] = h[x] + 1;         dfs(child);         siz[x] += siz[child] + 1;       }     }   }   int LCAH(int fi, int se) {     for (int i = maxlog - 1; i >= 0; i--)       if (par[fi][i] != par[se][i]) {         fi = par[fi][i];         se = par[se][i];       }     return n - siz[fi] - siz[se] - 2;   }   int LCA(int fi, int se) {     for (int i = maxlog - 1; i >= 0; i--)       if (h[par[fi][i]] >= h[se]) fi = par[fi][i];     if (fi == se) return fi;     for (int i = maxlog - 1; i >= 0; i--)       if (par[fi][i] != par[se][i]) {         fi = par[fi][i];         se = par[se][i];       }     return par[fi][0];   }   int main() {     cin >> n;     for (int i = 1; i < n; i++) {       int fi, se;       cin >> fi >> se;       adj[fi].push_back(se);       adj[se].push_back(fi);     }     dfs(1);     for (int j = 1; j < maxlog; j++)       for (int i = 1; i <= n; i++) par[i][j] = par[par[i][j - 1]][j - 1];     int q;     cin >> q;     while (q--) {       int fi, se;       cin >> fi >> se;       if (h[fi] < h[se]) swap(fi, se);       int dis = h[fi] + h[se] - 2 * h[LCA(fi, se)];       if (fi == se)         cout << n << endl;       else if (dis % 2 == 1)         cout << 0 << endl;       else if (h[fi] == h[se]) {         cout << LCAH(fi, se) << endl;       } else {         dis /= 2;         se = fi;         for (int i = maxlog - 1; i >= 0; i--) {           if ((1 << i) & dis) {             fi = par[fi][i];           }         }         int k = dis - 1;         for (int i = maxlog - 1; i >= 0; i--) {           if ((1 << i) & k) {             se = par[se][i];           }         }         cout << siz[fi] - siz[se] << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int ALPHABETS = 30;   const int maxN = 410;   bitset<maxN> orig[ALPHABETS][maxN], ans[maxN];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int N, M;     cin >> N >> M;     string s;     for (int i = 0; i < N; i++) {       cin >> s;       for (int j = 0; j < M; j++) {         orig[s[j] -  a ][i][j] = true;         ans[i][j] = true;       }     }     int R, C;     cin >> R >> C;     for (int i = 0; i < R; i++) {       cin >> s;       for (int j = 0; j < C; j++) {         if (s[j] ==  ? ) continue;         char ch = s[j] -  a ;         int goForward = j % M;         for (int k = 0; k < N; k++) {           int origR = (((k - i) % N) + N) % N;           ans[origR] &=               (orig[ch][k] >> goForward) | (orig[ch][k] << (M - goForward));         }       }     }     for (int i = 0; i < N; i++) {       for (int j = 0; j < M; j++) {         if (ans[i][j])           cout <<  1 ;         else           cout <<  0 ;       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int n;     std::cin >> n;     int t, c;     int max = 0, cur = 0, lt = -1;     for (int i = 0; i < n; i++) {       std::cin >> t >> c;       if (lt != -1) {         cur += lt - t;       }       if (cur < 0) cur = 0;       cur += c;       if (cur > max) max = cur;       lt = t;     }     if (cur < c) cur = c;     std::cout << lt + cur <<     << max;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 7;   const int N = 230;   const int M = 3500;   int m, n;   int a[N], b[N];   long long dp[M][N];   int main() {     cin >> m >> n;     memset(dp, 0, sizeof(dp));     for (int i = 0; i < m; ++i) {       cin >> a[i] >> b[i];       dp[a[i]][i]++;       if (a[i] != b[i]) {         a[i + m] = b[i];         b[i + m] = a[i];         dp[a[i + m]][i + m]++;       }     }     for (int i = 1; i <= n; ++i) {       for (int j = 0; j < m * 2; ++j) {         if (!dp[i][j]) continue;         for (int k = 0; k < 2 * m; ++k) {           if (j % m != k % m && a[k] == b[j])             dp[i + a[k]][k] = (dp[i + a[k]][k] + dp[i][j]) % inf;         }       }     }     long long ans = 0;     for (int i = 0; i < 2 * m; ++i) ans = (ans + dp[n][i]) % inf;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200100;   int main() {     int n = 0, u = 0, v = 0;     int d[MAXN] = {0};     scanf( %d , &n);     for (int i = 0; i < n - 1; i++) {       scanf( %d %d , &u, &v);       d[u] += 1;       d[v] += 1;     }     for (int i = 1; i <= n; i++) {       if (d[i] == 2) {         printf( NO n );         return 0;       }     }     printf( YES n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long x, y, n, c;   bool check(long long t) {     long long ans = 2 * t * t + 2 * t + 1;     if (x + t > n) {       long long m = x + t - n;       ans -= m * m;     }     if (y + t > n) {       long long m = y + t - n;       ans -= m * m;     }     if (x <= t) {       long long m = t - x + 1;       ans -= m * m;     }     if (y - t <= 0) {       long long m = t - y + 1;       ans -= m * m;     }     if (x - 1 + y - 1 < t) {       long long a = t - (x - 1 + y - 1) - 1;       ans += a * (a + 1) / 2;     }     if (x - 1 + n - y < t) {       long long a = t - (x - 1 + n - y) - 1;       ans += a * (a + 1) / 2;     }     if (n - x + y - 1 < t) {       long long a = t - (n - x + y - 1) - 1;       ans += a * (a + 1) / 2;     }     if (n - x + n - y < t) {       long long a = t - (n - x + n - y) - 1;       ans += a * (a + 1) / 2;     }     return ans >= c;   }   int main() {     while (cin >> n >> x >> y >> c) {       long long low = 0, high = 2 * n, mid, ans = 0;       while (low <= high) {         mid = (low + high) / 2;         if (check(mid)) {           ans = mid;           high = mid - 1;         } else           low = mid + 1;       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void gk() {     ios_base::sync_with_stdio(0);     cin.tie(0);     std::cout.tie(0);   }   int64_t mul(int64_t a, int64_t b) { return (a * b) % (int64_t)1000000007; }   int64_t gcd(int64_t a, int64_t b) {     if (b == 0) {       return a;     }     return gcd(b, a % b);   }   const int64_t sz = 2502;   const int64_t sz2 = 2e6 + 5;   int64_t row[4] = {1, -1, 0, 0};   int64_t col[4] = {0, 0, -1, 1};   int64_t val[sz];   int64_t n;   void find() {     int64_t n;     cin >> n;     vector<int64_t> ar(n);     unordered_set<int64_t> ans;     unordered_set<int64_t> curr;     for (int64_t i = 0; i < n; i++) {       cin >> ar[i];     }     ans.insert(ar[0]);     curr.insert(ar[0]);     for (int64_t i = 1; i < n; i++) {       unordered_set<int64_t> aux;       for (int64_t j : curr) {         aux.insert(j | ar[i]);       }       aux.insert(ar[i]);       curr = aux;       for (int64_t i : curr) {         ans.insert(i);       }     }     cout << ans.size();   }   int32_t main() {     int64_t t = 1;     while (t--) {       find();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   int cycl[N], set_val[N], cycl_size[N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int h, m, n;     cin >> h >> m >> n;     vector<int> strt;     bool vis[h];     memset(vis, false, sizeof vis);     int kk = 0;     set<int> dmm[h + 1];     for (long long i = 0; i < m; i++) {       if (vis[i]) {         continue;       }       int ii = i;       int jp = 0;       while (1) {         if (vis[ii]) {           break;         }         set_val[ii] = jp;         cycl[ii] = kk;         dmm[kk].insert(jp);         vis[ii] = true;         ii += m;         ii %= h;         jp++;       }       cycl_size[kk] = jp;       kk++;     }     map<int, int> hash;     map<int, int> final;     long long cnt = 0;     while (n--) {       char ch;       cin >> ch;       if (ch ==  + ) {         int id, t;         cin >> id >> t;         hash[id] = t;         if (dmm[cycl[t]].find(set_val[t]) != dmm[cycl[t]].end()) {           final[id] = set_val[t];           dmm[cycl[t]].erase(set_val[t]);           continue;         }         set<int>::iterator it, it1;         it = dmm[cycl[t]].lower_bound(set_val[t]);         int xx1;         if (it == dmm[cycl[t]].end()) {           it = dmm[cycl[t]].begin();           xx1 = cycl_size[cycl[t]] + *it - set_val[t];           int jj = *it;           final[id] = jj;           dmm[cycl[t]].erase(jj);         } else {           xx1 = *it - set_val[t];           int jj = *it;           final[id] = jj;           dmm[cycl[t]].erase(jj);         }         cnt += (long long)xx1;       } else {         int id;         cin >> id;         dmm[cycl[hash[id]]].insert(final[id]);       }     }     cout << cnt << endl;   }