malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   bool check_lucky(long long num) {     while (num) {       if ((num % 10) == 8) return 1;       num /= 10;     }     return 0;   }   int main() {     long long num;     cin >> num;     int flag = 0, ans = 1, f2 = 0;     if (num < 0) {       flag = 1;       num *= (-1);     }     if (flag) {       num--;       while (1) {         if (num == 0) {           f2 = 1;         }         if (f2) {           ans++;           if (!num) {             num++;             continue;           }           if (check_lucky(num)) {             cout << ans - 1 << endl;             return 0;           }           num++;         } else {           ans++;           if (check_lucky(num)) {             cout << ans - 1 << endl;             return 0;           }           num--;         }       }     } else {       num++;       while (1) {         ans++;         if (!num) continue;         if (check_lucky(num)) {           cout << ans - 1 << endl;           return 0;         }         num++;       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long n, ans, a[300123], maxx[300123], minx[300123], box[800123];   void dopart(long long l, long long r) {     if (l == r) {       ans++;       return;     }     long long mid = (l + r) / 2;     dopart(l, mid);     dopart(mid + 1, r);     maxx[mid] = a[mid], minx[mid] = a[mid];     for (long long i = mid - 1; i >= l; i--) {       maxx[i] = max(maxx[i + 1], a[i]), minx[i] = min(minx[i + 1], a[i]);     }     maxx[mid + 1] = a[mid + 1], minx[mid + 1] = a[mid + 1];     for (long long i = mid + 2; i <= r; i++) {       maxx[i] = max(maxx[i - 1], a[i]), minx[i] = min(minx[i - 1], a[i]);     }     for (long long i = mid; i >= l; i--) {       long long now = maxx[i] - minx[i];       if (i + now <= mid || i + now > r) continue;       if (maxx[now + i] <= maxx[i] && minx[now + i] >= minx[i]) ans++;     }     for (long long i = mid + 1; i <= r; i++) {       long long now = maxx[i] - minx[i];       if (i - now >= mid + 1 || i - now < l) continue;       if (maxx[i - now] <= maxx[i] && minx[i - now] >= minx[i]) ans++;     }     long long you1 = mid + 1, you2 = mid + 1;     for (long long i = mid; i >= l; i--) {       while (you2 <= r && maxx[you2] < maxx[i]) box[minx[you2] + you2]++, you2++;       while (you1 < you2 && minx[you1] > minx[i])         box[minx[you1] + you1]--, you1++;       ans = ans + box[i + maxx[i]];     }     for (long long i = you1; i < you2; i++) box[minx[i] + i]--;     long long zuo1 = mid, zuo2 = mid;     for (long long i = mid + 1; i <= r; i++) {       while (zuo1 >= l && maxx[zuo1] < maxx[i])         box[minx[zuo1] - zuo1 + n + 1]++, zuo1--;       while (zuo2 > zuo1 && minx[zuo2] > minx[i])         box[minx[zuo2] - zuo2 + n + 1]--, zuo2--;       ans = ans + box[maxx[i] - i + n + 1];     }     for (long long i = zuo2; i > zuo1; i--) box[minx[i] - i + n + 1]--;   }   int main() {     cin >> n;     for (long long i = 1; i <= n; i++) {       long long p, q;       cin >> p >> q;       a[p] = q;     }     dopart(1, n);     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const double eps = 1e-9;   const int inf = 2000000000;   const long long infLL = 9000000000000000000;   inline bool checkBit(long long n, int i) { return n & (1LL << i); }   inline long long setBit(long long n, int i) {     return n | (1LL << i);     ;   }   inline long long resetBit(long long n, int i) { return n & (~(1LL << i)); }   int fx[] = {0, 0, +1, -1};   int fy[] = {+1, -1, 0, 0};   inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }   inline bool isLeapYear(long long year) {     return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);   }   inline void normal(long long &a) {     a %= 998244353;     (a < 0) && (a += 998244353);   }   inline long long modMul(long long a, long long b) {     a %= 998244353, b %= 998244353;     normal(a), normal(b);     return (a * b) % 998244353;   }   inline long long modAdd(long long a, long long b) {     a %= 998244353, b %= 998244353;     normal(a), normal(b);     return (a + b) % 998244353;   }   inline long long modSub(long long a, long long b) {     a %= 998244353, b %= 998244353;     normal(a), normal(b);     a -= b;     normal(a);     return a;   }   inline long long modPow(long long b, long long p) {     long long r = 1;     while (p) {       if (p & 1) r = modMul(r, b);       b = modMul(b, b);       p >>= 1;     }     return r;   }   inline long long modInverse(long long a) { return modPow(a, 998244353 - 2); }   inline long long modDiv(long long a, long long b) {     return modMul(a, modInverse(b));   }   inline bool isInside(pair<int, int> p, long long n, long long m) {     return (p.first >= 0 && p.first < n && p.second >= 0 && p.second < m);   }   inline bool isInside(pair<int, int> p, long long n) {     return (p.first >= 0 && p.first < n && p.second >= 0 && p.second < n);   }   inline bool isSquare(long long x) {     long long s = sqrt(x);     return (s * s == x);   }   inline bool isFib(long long x) {     return isSquare(5 * x * x + 4) || isSquare(5 * x * x - 4);   }   inline bool isPowerOfTwo(long long x) {     return ((1LL << (long long)log2(x)) == x);   }   struct func {     bool operator()(pair<int, int> const &a, pair<int, int> const &b) {       if (a.first == b.first) return (a.second < b.second);       return (a.first < b.first);     }   };   long long corner(long long n, long long i) {     return (((n - i - 1ll) >= 0) ? modMul(180ll, modPow(10ll, n - i - 1ll)) : 0);   }   long long middle(long long n, long long i) {     return (((n - i - 2) >= 0)                 ? modMul(n - i - 1, modMul(810ll, modPow(10ll, n - i - 2)))                 : 0);   }   long long getResult(long long n, long long i) {     if (i == n) return 10;     return modAdd(corner(n, i), middle(n, i));   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n;     cin >> n;     for (int i = 1; i <= n; ++i) {       cout << getResult(n, i) <<    ;     }     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int modu = 1e9 + 7;   long long int mod(long long int n) { return (n % modu); }   bool cmp(long long int a, long long int b) { return a > b; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int N, a, b, c, d, x = 0;     pair<int, int> P[205], s;     cin >> N;     for (int i = 0; i < N; i++) {       cin >> P[i].first >> P[i].second;     }     for (int i = 0; i < N; i++) {       a = b = c = d = 0;       s.first = P[i].first;       s.second = P[i].second;       for (int j = 0; j < N; j++) {         if (i != j) {           if (P[j].first > s.first && P[j].second == s.second)             a = 1;           else if (P[j].first < s.first && P[j].second == s.second)             b = 1;           else if (P[j].first == s.first && P[j].second > s.second)             c = 1;           else if (P[j].first == s.first && P[j].second < s.second)             d = 1;         }       }       if (a == 1 && b == 1 && c == 1 && d == 1) x++;     }     cout << x;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, n, q = 0, z = 0;     cin >> a >> b >> n;     for (int i = 0; n >= 0; ++i) {       for (int j = a; j >= 1; --j) {         if (a % j == 0 && n % j == 0) {           q = n;           n = n - j;           break;         }       }       if (n >= 0) {         for (int c = b; c >= 1; --c) {           if (b % c == 0 && n % c == 0) {             z = n;             n = n - c;             break;           }         }       }     }     if (z == 0) {       cout <<  0 ;     }     if (q == 0) {       cout <<  1 ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3077;   int n, m, p, k, s[N], t[N], ls[N], nxt[N];   long long ans;   vector<int> P[N];   int main() {     scanf( %d%d%d%d , &n, &m, &p, &k);     for (int i = 1; i <= p; i++) {       int x, y;       scanf( %d%d , &x, &y);       P[x].push_back(y);     }     for (int u = n; u >= 1; u--) {       for (int i = 0; i < P[u].size(); i++) ++s[P[u][i]];       int l = 1, r = 0, yjy = 0;       long long aii = 0;       while (1) {         while (r + 1 <= m && yjy < k) yjy += s[++r];         if (yjy < k) break;         while (l <= r && yjy >= k) yjy -= s[l++], aii += m - r + 1;       }       for (int i = 1; i <= m; i++) t[i] = s[i];       for (int i = 0; i <= m + 1; i++) ls[i] = i - 1, nxt[i] = i + 1;       for (int i = 1; i <= m; i++)         if (!s[i]) ls[nxt[i]] = ls[i], nxt[ls[i]] = nxt[i];       for (int d = n; d >= u; d--) {         ans += aii;         for (int i = 0; i < P[d].size(); i++) {           int s = P[d][i], sl = t[s], sr = 0;           l = r = s;           while (nxt[r] <= m && sl + sr + t[nxt[r]] <= k) sr += t[r = nxt[r]];           while (1) {             if (sl + sr == k) aii -= (l - ls[l]) * (nxt[r] - r);             sl += t[l = ls[l]];             if (!l || sl > k) break;             while (sl + sr > k) sr -= t[r], r = ls[r];           }           --t[s];           if (!t[s]) ls[nxt[s]] = ls[s], nxt[ls[s]] = nxt[s];         }       }     }     printf( %lld , ans);   }
#include <bits/stdc++.h>   const long long mod = 998244353;   using namespace std;   pair<long long, long long> dp[20][2][1 << 10];   int k;   int s[20];   long long pw[20];   pair<long long, long long> solve(int i, bool U, int mask) {     if (i < 0) return {0, 1};     pair<long long, long long> &ret = dp[i][U][mask];     if (ret.first + 1) return ret;     ret = {0, 0};     int L = U ? 9 : s[i];     for (int e = 0; e <= L; e++) {       int Mask = mask | (mask > 0 ? (1 << e) : ((e > 0) * (1 << e)));       if (__builtin_popcount(Mask) > k) continue;       pair<long long, long long> temp = solve(i - 1, U || e < s[i], Mask);       ret.first += temp.first + temp.second * e % mod * pw[i] % mod;       ret.first %= mod;       ret.second += temp.second;       ret.second %= mod;     }     return ret;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     pw[0] = 1;     for (int i = 1; i <= 18; i++) pw[i] = pw[i - 1] * 10LL % mod;     long long l, r;     cin >> l >> r >> k;     for (int i = 0; i < 18; i++) s[i] = r % 10, r /= 10;     memset(dp, -1, sizeof dp);     long long ans = solve(17, 0, 0).first;     l--;     for (int i = 0; i < 18; i++) s[i] = l % 10, l /= 10;     memset(dp, -1, sizeof dp);     cout << ((ans - solve(17, 0, 0).first) % mod + mod) % mod;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long M = 1e9 + 7;   long long cnt[3000005], pre[3000005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     ;     long long n;     scanf( %lld , &n);     long long a;     for (long long i = 0; i < n; i++) {       scanf( %lld , &a);       cnt[a]++;     }     for (long long i = 1; i < 3000005; i++) {       for (long long j = 1; i * j < 3000005; j++) {         if (i == j)           pre[i * j] += (cnt[i] * (cnt[i] - 1));         else           pre[i * j] += cnt[i] * cnt[j];       }     }     for (long long i = 1; i < 3000005; i++) pre[i] += pre[i - 1];     long long m, p, an = 0, tot = (n * (n - 1));     scanf( %lld , &m);     for (long long i = 0; i < m; i++) {       scanf( %lld , &p);       an = tot - pre[p - 1];       printf( %lld n , an);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> darmo;   vector<pair<int, int> > tab;   vector<bool> done;   vector<int> wolne;   int n, k;   int main() {     scanf( %d %d , &n, &k);     darmo.resize(n);     tab.resize(n);     done.resize(k + 1, false);     long long res = 0;     for (int i = 0; i < n; i++) scanf( %d , &darmo[i]);     for (int i = 0; i < n; i++) {       scanf( %d , &tab[i].first);       tab[i].second = i;     }     sort(tab.begin(), tab.end());     reverse(tab.begin(), tab.end());     for (int i = 0; i < n; i++) {       if (!done[darmo[tab[i].second]]) {         done[darmo[tab[i].second]] = true;       } else         wolne.push_back(tab[i].first);     }     sort(wolne.begin(), wolne.end());     int x = 0;     for (int i = 1; i < k + 1; i++)       if (!done[i]) {         res += (long long)wolne[x];         x++;       }     printf( %lld n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, q, res[111][111];   pair<int, int> pos[111][111];   int type, r, c, x;   int main() {     scanf( %d %d %d , &n, &m, &q);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) pos[i][j] = pair<int, int>(i, j);     while (q--) {       scanf( %d , &type);       if (type == 1) {         scanf( %d , &r);         for (int i = 0; i < m; ++i) pos[r][i] = pos[r][i + 1];         pos[r][m] = pos[r][0];       } else if (type == 2) {         scanf( %d , &c);         for (int i = 0; i < n; ++i) pos[i][c] = pos[i + 1][c];         pos[n][c] = pos[0][c];       } else {         scanf( %d %d %d , &r, &c, &x);         res[pos[r][c].first][pos[r][c].second] = x;       }     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) printf( %d  , res[i][j]);       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 105;   char mp[3][N], tmp[3][N], g[55][3][N];   bool vis[55][3][N];   int n, k;   void getNext(int id) {     memcpy(g[id], mp, sizeof(mp));     for (int i = int(0); i <= int((3) - 1); i++)       for (int j = int(1); j <= int(n - 3); j++) tmp[i][j] = mp[i][j + 3];     for (int i = int(0); i <= int((3) - 1); i++)       tmp[i][n - 2] = tmp[i][n - 1] = tmp[i][n] =  . ;     memcpy(mp, tmp, sizeof(tmp));   }   int dx[] = {0, -1, 1}, dy[] = {0, 0, 0};   bool good(int now, int x, int y) {     return x >= 0 && x < 3 && g[now][x][y] ==  .  && g[now - 1][x][y + 1] ==  . ;   }   bool bfs(int sx, int sy) {     memset(vis, 0, sizeof(vis));     int now = 0, x = sx, y = sy;     queue<int> q;     q.push(now), q.push(x);     while (q.size()) {       now = q.front();       q.pop();       x = q.front();       q.pop();       if (now > 50) {         return 1;       }       for (int i = int(0); i <= int((3) - 1); i++) {         if (g[now][x][y + 1] !=  . ) continue;         int tx = x + dx[i];         if (good(now + 1, tx, y)) {           if (!vis[now + 1][tx][y]) {             q.push(now + 1), q.push(tx);             vis[now + 1][tx][y] = 1;           }         }       }     }     return 0;   }   int main() {     ios::sync_with_stdio(0);     int t;     cin >> t;     while (t--) {       cin >> n >> k;       for (int i = int(0); i <= int((3) - 1); i++) {         cin >> (mp[i] + 1);       }       int sx, sy;       for (int i = int(0); i <= int((3) - 1); i++) {         for (int j = int(1); j <= int(n); j++)           if (mp[i][j] ==  s ) {             sx = i, sy = j;             mp[i][j] =  . ;           }       }       for (int i = int(0); i <= int((54) - 1); i++) getNext(i);       if (bfs(sx, sy))         puts( YES );       else         puts( NO );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 100;   char num[maxn];   char num2[maxn];   vector<int> vec;   queue<int> que;   inline int read() {     char ch = getchar();     int x = 0, f = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while ( 0  <= ch && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int main() {     int n = read(), sx = read(), sy = read();     int s1 = 0, s2 = 0, s3 = 0, s4 = 0;     int u = 0, d = 0, l = 0, r = 0;     for (int i = 1; i <= n; ++i) {       int x, y;       scanf( %d%d , &x, &y);       if (x < sx) {         if (y < sy) {           s2++;           s4++;         } else if (y > sy) {           s2++;           s3++;         } else if (y == sy) {           d++;         }       } else if (x > sx) {         if (y < sy) {           s1++;           s4++;         } else if (y > sy) {           s1++;           s3++;         } else {           u++;         }       } else if (x == sx) {         if (y < sy) {           l++;         } else if (y > sy) {           r++;         } else {           continue;         }       }     }     int num1 = s1 + u;     int num2 = s3 + r;     int num3 = s2 + d;     int num4 = s4 + l;     if (num1 >= num2 && num1 > num3 && num1 >= num4) {       printf( %d n , num1);       printf( %d %d n , sx + 1, sy);     } else if (num2 >= num1 && num2 > num3 && num2 >= num4) {       cout << num2 << endl;       printf( %d %d n , sx, sy + 1);     } else if (num3 >= num2 && num3 > num1 && num3 >= num4) {       cout << num3 << endl;       printf( %d %d n , sx - 1, sy);     } else if (num4 >= num2 && num4 > num3 && num4 >= num1) {       cout << num4 << endl;       printf( %d %d n , sx, sy - 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2 * 100000, maxk = 2 * 100000, inf = 0x3f3f3f3f;   int n, k, s, t;   struct car {     int c, v;   } a[maxn + 10];   int d[maxk + 10];   int ans = inf;   void init() {     scanf( %d%d%d%d , &n, &k, &s, &t);     for (int i = 1; i <= n; i++) scanf( %d%d , &a[i].c, &a[i].v);     for (int i = 1; i <= k; i++) scanf( %d , &d[i]);     d[k + 1] = s;   }   bool cmp(car x, car y) { return x.v < y.v; }   bool check(int x) {     double time = 0;     for (int i = 1; i <= k + 1; i++) {       double x1, x2;       int tmp = d[i] - d[i - 1];       x1 = (double)(max(0, 2 * tmp - a[x].v));       x2 = 2 * (tmp - x1);       if (x2 < 0) return false;       time += 2 * x1 + x2 / 2;       if (time > t) return false;     }     return true;   }   void solve() {     sort(a + 1, a + 1 + n, cmp);     sort(d + 1, d + 1 + k + 1);     int l = 1, r = n;     int mm = 0;     while (l <= r) {       int mid = (l + r) >> 1;       if (check(mid))         mm = mid, r = mid - 1;       else         l = mid + 1;     }     if (mm == 0)       printf( -1 );     else {       for (int i = mm; i <= n; i++) ans = min(ans, a[i].c);       printf( %d n , ans);     }   }   int main() {     init();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int sol(const vector<long long>& a, int n, int m, long long t) {     long long s = 0;     for (int i = 0; i < m; i++) s += a[i];     int ans = 0;     for (int i = 0; i <= n && s * i <= t; i++) {       int cnt = (m + 1) * i;       long long r = t - s * i;       for (int j = 0; j < m && r >= a[j]; j++) {         int c = min(r / a[j], (long long)(n - i));         r -= a[j] * c;         cnt += c;       }       ans = max(ans, cnt);     }     return ans;   }   int main() {     int n, m;     long long t;     scanf( %d%d%lld , &n, &m, &t);     vector<long long> a(m);     for (int i = 0; i < m; i++) scanf( %lld , &a[i]);     sort(a.begin(), a.end());     printf( %d n , sol(a, n, m, t));   }
#include <bits/stdc++.h>   using namespace std;   inline const int getint() {     int r = 0, k = 1;     char c = getchar();     for (; c <  0  || c >  9 ; c = getchar())       if (c ==  - ) k = -1;     for (; c >=  0  && c <=  9 ; c = getchar()) r = r * 10 + c -  0 ;     return k * r;   }   long long ans, a1, b1, a2, b2, t1, t2;   int main() {     cin >> a1 >> b1 >> a2 >> b2;     long long a = a1 * b1, b = a2 * b2;     while (a % 3 == 0) ++t1, a /= 3;     while (b % 3 == 0) ++t2, b /= 3;     ans += abs(t1 - t2);     while (t1 > t2 && a1 % 3 == 0) a1 -= a1 / 3, --t1;     while (t1 > t2 && b1 % 3 == 0) b1 -= b1 / 3, --t1;     while (t1 < t2 && a2 % 3 == 0) a2 -= a2 / 3, --t2;     while (t1 < t2 && b2 % 3 == 0) b2 -= b2 / 3, --t2;     a = a1 * b1, b = a2 * b2;     t1 = t2 = 0;     while (a % 2 == 0) ++t1, a /= 2;     while (b % 2 == 0) ++t2, b /= 2;     ans += abs(t1 - t2);     while (t1 > t2 && a1 % 2 == 0) a1 -= a1 / 2, --t1;     while (t1 > t2 && b1 % 2 == 0) b1 -= b1 / 2, --t1;     while (t1 < t2 && a2 % 2 == 0) a2 -= a2 / 2, --t2;     while (t1 < t2 && b2 % 2 == 0) b2 -= b2 / 2, --t2;     if (a1 * b1 != a2 * b2) {       puts( -1 );       return 0;     }     cout << ans << endl << a1 <<     << b1 << endl << a2 <<     << b2;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 19, N = (1 << M);   int a[N];   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     int id = -1;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] == -1) id = i;     }     int rem = n - id - 1;     int t = 0;     long long ans = 0;     while (rem > 0) {       int mn = n - 1;       for (int i = n - 1; i >= n / (1 << t) - 1; i--)         if (a[mn] > a[i]) mn = i;       ans += a[mn];       a[mn] = 1e9 + 10;       rem -= n / (1 << (t + 1));       t++;       assert(t <= 20);       cerr << t <<   ****  n ;     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int n, t;   int main() {     cin >> n >> t;     long long z = pow(10, n - 2);     if (n == 1 and t == 10) return cout << -1 << endl, 0;     if (n == 1) return cout << t << endl, 0;     if (t == 2 or t == 4 or t == 5 or t == 8 or t == 10)       cout << 40;     else if (t == 7)       cout << 14;     else       cout << 18;     n -= 2;     while (n) {       cout <<  0 ;       n--;     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long t, n, sum, t1, ans;   string st;   int main() {     cin >> t;     while (t--) {       cin >> n;       cin >> st;       int a = 0, b = 0;       for (int i = 0; i < n; i++) {         if (st[i] ==  ( ) a++;         if (st[i] ==  ) ) {           if (a)             a--;           else             b++;         }       }       cout << min(a, b) <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     for (int i = 0; i < t; i++) {       int n, count = 1;       cin >> n;       while (n > 0) {         if (count % 3 != 0 && count % 10 != 3) {           count++;           n--;         } else {           count++;         }       }       int ans = count - 1;       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1 << 23;   const int offset = (int)1e6;   int st_sum[2 * N];   int st_ma[2 * N];   int getMax(int a, int b) {     a += N + offset;     b += N + offset;     int ma = -1e9;     int sum_a = 0;     int ma_b = 0;     for (; a < b; a /= 2, b /= 2) {       if (a % 2 == 1) {         ma = max(ma, st_ma[a] + sum_a);         sum_a += st_sum[a];         ++a;       }       if (b % 2 == 0) {         ma_b = max(ma_b + st_sum[b], st_ma[b]);         --b;       }     }     if (a == b) {       ma = max(ma, st_ma[a] + sum_a);       sum_a += st_sum[a];     }     ma = max(ma, sum_a + ma_b);     return ma;   }   void updateSegtreePos(int pos) {     st_sum[pos] = st_sum[pos * 2] + st_sum[pos * 2 + 1];     st_ma[pos] = max(st_ma[pos * 2], st_sum[pos * 2] + st_ma[pos * 2 + 1]);   }   void addValue(int pos, int val) {     pos += N + offset;     st_sum[pos] += val;     st_ma[pos] += val;     for (pos /= 2; pos; pos /= 2) {       updateSegtreePos(pos);     }   }   set<int> pawns[(int)2e5 + 10];   multiset<int> intercept_ys;   int main() {     int n, k, m;     cin >> n >> k >> m;     for (int i = 0; i < N; ++i) {       st_sum[i + N] = -1;       st_ma[i + N] = -1;     }     for (int i = N - 1; i; --i) {       updateSegtreePos(i);     }     for (int i = 0; i < m; ++i) {       int x, y;       cin >> x >> y;       int intercept_y = (n - y) - abs(x - k);       if (pawns[x].count(y)) {         addValue(intercept_y, -1);         pawns[x].erase(y);         intercept_ys.erase(intercept_ys.find(intercept_y));       } else {         addValue(intercept_y, 1);         pawns[x].insert(y);         intercept_ys.insert(intercept_y);       }       if (intercept_ys.size()) {         cout << max(0, getMax(*intercept_ys.begin(), n) - *intercept_ys.begin())              << endl;       } else {         cout << 0 << endl;       }     }   }