malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   using namespace std;   using pii = pair<int, int>;   using pll = pair<long long, long long>;   using vb = vector<bool>;   using vi = vector<int>;   using vl = vector<long long>;   using vvb = vector<vector<bool>>;   using vvi = vector<vector<int>>;   using vvl = vector<vector<long long>>;   using vpii = vector<pair<int, int>>;   using mii = map<int, int>;   template <typename... ArgTypes>   void print(ArgTypes... args);   template <typename... ArgTypes>   void input(ArgTypes &...args);   template <>   void print() {}   template <>   void input() {}   template <typename T, typename... ArgTypes>   void print(T t, ArgTypes... args) {     cout << t;     print(args...);   }   template <typename T, typename... ArgTypes>   void input(T &t, ArgTypes &...args) {     cin >> t;     input(args...);   }   void traverse(int n, int mul) {     if (n == 0) return;     int a = n - n / 2, b = n - n / 3;     int x = 2, y = 3;     if (a >= b) {       swap(a, b);       swap(x, y);     }     for (int i = 1; i <= a; i++) cout << mul <<    ;     int remaining = n / x;     traverse(remaining, mul * x);   }   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     traverse(n, 1);   }
#include <bits/stdc++.h>   inline int two(int n) { return 1 << n; }   inline int test(int n, int b) { return (n >> b) & 1; }   inline void set_bit(int& n, int b) { n |= two(b); }   inline void unset_bit(int& n, int b) { n &= ~two(b); }   inline int last_bit(int n) { return n & (-n); }   inline int ones(int n) {     int res = 0;     while (n && ++res) n -= n & (-n);     return res;   }   long long int gcd(long long int a, long long int b) {     return (a ? gcd(b % a, a) : b);   }   long long int modPow(long long int a, long long int b, long long int MOD) {     long long int x = 1, y = a;     while (b > 0) {       if (b % 2 == 1) {         x = (x * y) % MOD;       }       b /= 2;       y = (y * y) % MOD;     }     return x;   }   long long int modInverse(long long int a, long long int p) {     return modPow(a, p - 2, p);   }   using namespace std;   const int N = 1e3 + 3;   int arr[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, i, j, l, r, taiyar, submit, ans, m;     ans = 0;     taiyar = 0;     submit = 0;     cin >> n;     for (int i = 0; i < (n); i++) {       cin >> arr[i];       taiyar += arr[i];     }     cin >> m;     while (m--) {       cin >> l >> r;       if (taiyar <= r) {         cout << max(taiyar, l);         return 0;       }     }     cout <<  -1 ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double eps = 1e-7;   int main() {     int t;     double a, b, ans;     scanf( %d , &t);     while (t--) {       scanf( %lf%lf , &a, &b);       ans = 0.50000000;       if (b < eps) {         printf( %lf n , 1.0);         continue;       }       if (a < eps) {         printf( %lf n , 0.5);         continue;       }       if (a / b - 4.0 < -eps) {         ans += 0.5 * (a * a / 8.0) / (a * b);       } else {         ans += 0.5 * (a * b - b * 2.0 * b) / (a * b);       }       printf( %lf n , ans);     }     return 0;   }
#include <bits/stdc++.h>   #define ll long long   #define II pair<int,int>   #define fi first   #define se second   #define task  test    using namespace std;      void Init(){       ios::sync_with_stdio(0);       cin.tie(0);cout.tie(0);   }      int n;   int a[200001];   int res;      int d(II &a,II &b){       return abs(a.fi-b.fi)+b.se-a.se;   }      bool Check(int i,int j,int k){       II p={a[i],i};       II q={a[j],j};       II r={a[k],k};       //int s=d( p,q )+d( q,r ),S=d( p,r );       //cout<<i<<   <<j<<   <<k<<   <<s<<   <<S<<  n ;       return( d( p,q )+d( q,r )==d( p,r ) );   }      bool Cal(int l,int r){       for(int i=l;i<r;++i)       for(int j=i+1;j<r;++j)       if(Check(i,j,r))return 1;       res++;       return 0;   }      void Solve(){       cin>>n;       while(cin>>n){           for(int i=1;i<=n;++i)cin>>a[i];              res=0;           for(int i=1;i<=n;++i)           for(int j=i+2;j<=n;++j){               if(Cal(i,j))break;               //cout<<i<<   <<j<<  n ;           }              cout<<res+n+n-1<<  n ;       }   }      int main(){       Init();       Solve();   }
#include <bits/stdc++.h>   using namespace std;   constexpr int MAXN = 128;   int type[MAXN][MAXN];   constexpr char* pat[6] = { #//. ,    #.  ,    .#  ,  .//# ,  .... ,  #### };   int main() {     int n, m, a, b, c, k, x, y;     scanf( %d%d , &n, &m);     scanf( %d%d%d , &a, &b, &c);     k = 0;     for (int i = 0; i < a; ++i, ++k) type[k / m][k % m] = 5;     y = k % m;     for (int i = 0; i < m; ++i, ++k)       type[k / m][k % m] = (((k % m - y) % 2 == 0) ^ (k % m < y)) ? 0 : 1;     for (int i = 0; i < b; ++i, ++k) type[k / m][k % m] = 4;     for (int i = m; i < c; ++i, ++k)       for (int j = 0; j < 4; ++j) {         x = k / m;         y = k % m;         if ((x == 0 || ((type[x - 1][y] ^ j) & 2) != 0) &&             (y == 0 || ((type[x][y - 1] ^ j) & 1) != 0)) {           type[k / m][k % m] = j;           break;         }       }     for (int i = 0; i < n + n; ++i) {       for (int j = 0; j < m + m; ++j)         putchar(pat[type[i / 2][j / 2]][i % 2 * 2 + j % 2]);       putchar(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int tata[2010], g[2010];   vector<pair<int, int>> edges;   bitset<2001> secret[2001];   int find(int x) {     return (tata[tata[x]] == tata[x] ? tata[x] : tata[x] = find(tata[x]));   }   void unite(int a, int b) {     a = find(a);     b = find(b);     assert(a != b);     if (g[a] >= g[b])       tata[b] = a, g[a] += g[b];     else       tata[a] = b, g[b] += g[a];   }   void test() {     edges.clear();     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       tata[i] = i, g[i] = 1;       secret[i] = bitset<2001>();     }     for (int i = 0; i < m; i++) {       string s;       cin >> s;       for (int j = 0; j < n; j++) secret[j][i] = s[j] -  0 ;     }     vector<pair<int, pair<int, int>>> ord;     for (int i = 0; i < n; i++)       for (int j = i + 1; j < n; j++)         ord.push_back({(secret[i] & secret[j]).count(), {i, j}});     sort(ord.rbegin(), ord.rend());     for (auto i : ord) {       if (find(i.second.first) == find(i.second.second)) continue;       unite(i.second.first, i.second.second);       edges.push_back({i.second.first, i.second.second});     }     for (int i = 0; i < m; i++) {       int nr = 0;       for (int j = 0; j < n; j++) nr += secret[j][i];       for (auto j : edges) nr -= secret[j.first][i] & secret[j.second][i];       if (nr != 1) {         cout <<  NO n ;         return;       }     }     cout <<  YES n ;     for (auto i : edges) cout << i.first + 1 <<     << i.second + 1 <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) test();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f, N = 10;   int ans = inf, n, k, idx[N];   char arr[N][N];   int convert(int num) {     int ret = 0;     for (int i = 0; i < k; ++i) {       ret = (ret * 10) + (arr[num][idx[i]] -  0 );     }     return ret;   }   int main() {     cin >> n >> k;     for (int i = 0; i < k; ++i) idx[i] = i;     for (int i = 0; i < n; ++i) scanf( %s , arr[i]);     do {       int mn = inf, mx = 0;       for (int i = 0; i < n; ++i) {         mn = min(mn, convert(i));         mx = max(mx, convert(i));       }       ans = min(ans, mx - mn);     } while (next_permutation(idx, idx + k));     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char* argv[]) {     int v1, v2, t, d, sum, a, t1, t2;     while (cin >> v1 >> v2 >> t >> d) {       sum = v1 + v2;       for (int i = 2; i < t; i++) {         if (v1 <= v2) {           v1 += d;           sum += v1;         } else {           v2 += d;           sum += v2;         }       }       cout << sum << endl;     }     return 0;   }
#include <bits/stdc++.h>   const int INF = 1e9 + 100;   const long long lINF = 4e18;   const double EPS = 1e-12;   using namespace std;   const int N = 5e5 + 100;   int n, k, h[N], s[N], mn = INF, mxh[N], should = INF;   vector<int> graph[N];   vector<int> can, need;   void dfs1(int v, int par = -1, int mx = INF) {     mxh[v] = mx;     mx = min(mx, h[v]);     can.push_back(mx);     for (auto j : graph[v]) {       if (j != par) dfs1(j, v, mx);     }   }   void dfs2(int v, int par, map<int, int>& ans) {     map<int, int> ans2;     for (auto j : graph[v]) {       if (j != par) {         dfs2(j, v, ans2);         if (ans.size() < ans2.size()) {           swap(ans, ans2);         }         for (auto k : ans2) {           ans[k.first] += k.second;         }         ans2.clear();       }     }     if (mxh[v] >= need[0] && h[v] <= should) {       bool flag = true;       ans[need[0]]++;       map<int, int>::reverse_iterator j = ans.rbegin();       for (int i = 0; i < (int)need.size(); i++) {         while (j != ans.rend() && j->second == 0) {           j++;         }         if (j == ans.rend() || j->first < need[i]) {           flag = false;         } else {           j->second--;         }       }       if (flag) {         mn = min(mn, need[0] - h[v]);       }       ans.clear();     } else {       while (ans.size() > 0 && ans.rbegin()->first > h[v]) {         int p = ans.rbegin()->second;         ans.erase(ans.rbegin()->first);         ans[h[v]] += p;       }       ans[h[v]]++;     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &h[i]);     }     for (int i = 0; i < n - 1; i++) {       int a, b;       scanf( %d%d , &a, &b);       graph[a].push_back(b);       graph[b].push_back(a);     }     scanf( %d , &k);     for (int i = 0; i < k; i++) {       scanf( %d , &s[i]);     }     dfs1(1);     sort(s, s + k);     reverse(s, s + k);     sort((can).begin(), (can).end());     reverse((can).begin(), (can).end());     for (int i = 0, j = 0, delta = 0; i < k; i++) {       delta--;       while (j < (int)can.size() && can[j] >= s[i]) {         j++;         delta++;       }       if (j < i + 1) {         should = min(should, s[i] - 1);       }       if (delta < 0) {         need.push_back(s[i]);         delta++;       }     }     if (need.size() == 0) {       cout << 0 << endl;     } else {       map<int, int> res;       dfs2(1, -1, res);       if (mn == INF) {         cout <<  -1  << endl;       } else {         cout << mn << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100000;   bool isprime[maxn];   int p[5], s[5], n;   const int tenpow[6] = {1, 10, 100, 1000, 10000, 100000};   int tenpowmul[6][10];   int getd[maxn][5];   int ans;   bool good[2 * maxn][6];   int tans[maxn];   void solve(int i) {     if (i == 0) {       for (int i = 0; i < n; ++i) s[i] = tenpowmul[n - 1][getd[p[0]][n - 1 - i]];       solve(i + 1);     } else if (i + 1 == n)       ans += tans[s[i]];     else       for (int j = 0; j < tenpow[n - i]; ++j)         if (isprime[s[i] + j]) {           p[i] = s[i] + j;           int y[5], k;           for (k = i; k < n; ++k) {             s[k] += (y[k] = tenpowmul[n - i - 1][getd[p[i]][n - k - 1]]);             if (!good[s[k]][n - i]) break;           }           if (k == n) solve(i + 1), k--;           for (; k >= i; --k) s[k] -= y[k];         }   }   int main() {     for (int i = 0; i < (int)(6); ++i)       for (int j = 0; j < (int)(10); ++j) tenpowmul[i][j] = tenpow[i] * j;     for (int i = 0; i < (int)(maxn); ++i)       for (int j = 0; j < (int)(5); ++j) getd[i][j] = (i / tenpow[j]) % 10;     for (int i = (int)(2); i <= (int)(maxn); ++i) isprime[i] = 1;     for (int i = 2; i * i < maxn; ++i)       if (isprime[i])         for (int j = i * i; j < maxn; j += i) isprime[j] = 0;     for (int i = 0; i < (int)(maxn); ++i) good[i][0] = isprime[i];     for (int j = (int)(1); j <= (int)(5); ++j)       for (int i = 0; i < (int)(maxn); ++i)         for (int k = 0; k < (int)(10); ++k)           good[i][j] |= good[i + tenpowmul[j - 1][k]][j - 1];     for (int i = 0; i < (int)(maxn); ++i)       if (i % 10 == 0)         for (int k = 0; k < (int)(10); ++k) tans[i] += isprime[i + k];     int T;     cin >> T;     for (int _t = 0; _t < (int)(T); ++_t) {       cin >> p[0];       int k = 1;       n = 0;       while (k <= p[0]) k *= 10, n += 1;       for (int i = (int)(1); i <= (int)(n - 1); ++i) p[i] = 0;       ans = 0;       solve(0);       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch - 48;       ch = getchar();     }     return x * f;   }   namespace star {   const int maxn = 2e5 + 5;   int head[maxn], len[maxn], dis[maxn], pre[maxn];   int n, cnt = 1, m, ans;   char ch[maxn];   bool vis[maxn];   priority_queue<pair<int, int> > q;   queue<int> qt;   struct edge {     int to, nxt, val;   } e[maxn];   void add(int u, int v, int w) {     e[++cnt].to = v;     e[cnt].val = w;     e[cnt].nxt = head[u];     head[u] = cnt;     e[++cnt].to = u;     e[cnt].val = w;     e[cnt].nxt = head[v];     head[v] = cnt;   }   inline void dijkstra() {     memset(pre, 0, sizeof(pre));     memset(dis, 0x3f, sizeof(dis));     memset(len, 0x3f, sizeof(len));     qt.push(n);     dis[n] = 0;     len[n] = 1;     while (!qt.empty()) {       int u = qt.front();       qt.pop();       q.push(make_pair(0, u));       for (int i = head[u]; i; i = e[i].nxt) {         int v = e[i].to;         int w = e[i].val;         if (dis[v] && w == 0) {           dis[v] = 0;           len[v] = len[u] + 1;           pre[v] = (i ^ 1);           qt.push(v);         }       }     }     int pos = 0, lst = -1;     while (!q.empty()) {       int u = q.top().second;       q.pop();       if (vis[u]) continue;       vis[u] = true;       if (lst != dis[u]) pos++, lst = dis[u];       for (int i = head[u]; i; i = e[i].nxt) {         int v = e[i].to;         int w = e[i].val;         if (dis[v] > pos * 10 + w) {           dis[v] = pos * 10 + w;           len[v] = len[u] + 1;           pre[v] = i ^ 1;           q.push(make_pair(-dis[v], v));         } else if (dis[v] == pos * 10 + w && len[v] > len[u] + 1) {           len[v] = len[u] + 1;           pre[v] = i ^ 1;           q.push(make_pair(-dis[v], v));         }       }     }   }   void work() {     n = read();     m = read();     for (int a, b, i = 1; i <= m; i++)       a = read() + 1, b = read() + 1, add(a, b, read());     dijkstra();     int tmp = 1;     stack<int> s;     while (tmp != n) {       s.push(e[pre[tmp]].val);       tmp = e[pre[tmp]].to;     }     while (!s.empty() && s.top() == 0) s.pop();     if (s.empty())       printf( 0 );     else       while (!s.empty()) printf( %d , s.top()), s.pop();     putchar(  n );     printf( %d n0  , len[1]);     tmp = 1;     while (tmp != n) {       tmp = e[pre[tmp]].to;       printf( %d  , tmp - 1);     }   }   }  // namespace star   signed main() {     star::work();     return 0;   }
#include <bits/stdc++.h>   using ll = long long;   using namespace std;   int main() {     cin.tie(0);     ios_base::sync_with_stdio(false);     int n, m;     char c;     cin >> n >> m >> c;     vector<string> vec(n);     for (int i = 0; i < n; ++i) {       cin >> vec[i];     }     unordered_set<char> s;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (vec[i][j] == c) {           if (i - 1 >= 0 && vec[i - 1][j] !=  .  && vec[i - 1][j] != c) {             s.insert(vec[i - 1][j]);           }           if (j - 1 >= 0 && vec[i][j - 1] !=  .  && vec[i][j - 1] != c) {             s.insert(vec[i][j - 1]);           }           if (i + 1 < n && vec[i + 1][j] !=  .  && vec[i + 1][j] != c) {             s.insert(vec[i + 1][j]);           }           if (j + 1 < m && vec[i][j + 1] !=  .  && vec[i][j + 1] != c) {             s.insert(vec[i][j + 1]);           }         }       }     }     cout << s.size() <<   n ;     return 0;   }
#include<bits/stdc++.h>      using namespace std;   #define show(x) cout<< #x <<  =   << x <<    n  ;   #define mod 998244353   #define INF 1000000000000000000   #define pie 3.14159265358979323846   #define ll long long int   #define pb push_back   #define popcnt __builtin_popcount   #define mp make_pair   #define pii pair<ll,ll>   #define prod(a,b) ((a*b)%mod)   #define set0(x) memset(x,0,sizeof(x))   #define setm1(x) memset(x,-1,sizeof(x))   #define printlist(arr) for(auto lstelem :arr) cout<< lstelem <<    ;cout<<   n     #define all(a) a.begin(),a.end()   #define sqre(a) ((a)*(a))      //maths stuff   ll powr(ll a,ll b){       ll res=1;       while(b){           if(b%2)               res=(a*res)%mod;           a=(a*a)%mod;           b/=2;       }       return res;   }      void extentded_eucledian(ll a,ll b,ll &ex,ll &ey){       if(b==0){           ex=1;           ey=0;           return;       }       extentded_eucledian(b,a%b,ex,ey);       swap(ex,ey);       ey-= (a/b)*ex;//gcd= x*a+y*b   }      ll dp[1002][1002][2];      int main(){        #ifdef ONLINE_JUDGE           //onlinesubmission       #else       freopen( input.txt , r ,stdin);       #endif       ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);       string x,y; cin>> x >> y ;       ll n=x.size(),m=y.size();       set0(dp);       ll ans=0;       for(ll i=0;i<=n;++i){           for(ll j=0;j<=m;++j){               if(i>0) dp[i][j][0]=(dp[i][j][0]+1)%mod;               if(j>0) dp[i][j][1]=(dp[i][j][1]+1)%mod;               if(i>1){                   if(x[i-1]!=x[i-2]) dp[i][j][0]=(dp[i][j][0]+dp[i-1][j][0])%mod;               }               if(i>0 && j>0){                   if(x[i-1]!=y[j-1]){                       dp[i][j][0]=(dp[i][j][0]+dp[i-1][j][1])%mod;                       dp[i][j][1]=(dp[i][j][1]+dp[i][j-1][0])%mod;                   }               }               if(j>1){                   if(y[j-1]!=y[j-2]) dp[i][j][1]=(dp[i][j][1]+dp[i][j-1][1])%mod;               }               ans=(ans+dp[i][j][0]+dp[i][j][1])%mod;           }       }       for(ll i=0;i<n;++i){           ll j=i;           while(j+1<n) if(x[j]!=x[j+1]) ++j; else break;           ll l=(j-i+1),v=(( ((l+1)*l/2)%mod )*(m+1))%mod;           ans=(ans-v+mod)%mod;           i=j;       }       for(ll i=0;i<m;++i){           ll j=i;           while(j+1<m) if(y[j]!=y[j+1]) ++j; else break;           ll l=(j-i+1),v=((((l+1)*l/2)%mod)*(n+1))%mod;           ans=(ans-v+mod)%mod;           i=j;       }       cout<< ans ;       return 0;   }      //might1331 pratapSingh: Try Kr raha hu mai bc, timer laga rakha h
#include <bits/stdc++.h>   using namespace std;   bool prime(long long x) {     if (x == 2) {       return true;     }     if (x <= 1) {       return false;     }     for (int i = 2; i < sqrt(x); i++) {       if (x % i == 0) {         return false;       }     }     return true;   }   void printv(vector<long long> v) {     for (int i = 0; i < v.size(); i++) {       cout << v[i] <<    ;     }     cout << endl;   }   string Y =  YES n ;   string N =  NO n ;   int rec(string s, int pos, int team1, int team2) {     if (team1 < team2) {       if (5 - (ceil((pos * 1.0) / 2)) < (team2 - team1)) {         return pos;       }     } else {       if (5 - (pos / 2) < (team1 - team2)) {         return pos;       }     }     if (pos == 10) {       return 10;     }     int h = 10;     if (pos % 2 == 0) {       if (s[pos] ==  1 ) {         h = min(h, rec(s, pos + 1, team1 + 1, team2));       } else if (s[pos] ==  0 ) {         h = min(h, rec(s, pos + 1, team1, team2));       } else {         int x =             min(rec(s, pos + 1, team1 + 1, team2), rec(s, pos + 1, team1, team2));         h = min(x, h);       }     } else {       if (s[pos] ==  1 ) {         h = min(h, rec(s, pos + 1, team1, team2 + 1));       } else if (s[pos] ==  0 ) {         h = min(h, rec(s, pos + 1, team1, team2));       } else {         int x =             min(rec(s, pos + 1, team1, team2 + 1), rec(s, pos + 1, team1, team2));         h = min(x, h);       }     }     return h;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     for (int pop = 0; pop < t; pop++) {       string q;       cin >> q;       int c = rec(q, 0, 0, 0);       cout << c << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int k[3];   int t[3];   long long a[100010];   struct mydata {     int idx;     long long x;     bool operator<(const mydata &r) const {       if (x == r.x)         return idx < r.idx;       else         return x < r.x;     }   } b[100010];   std::priority_queue<long long, vector<long long>, greater<long long> > Q;   int main() {     int i;     cin >> k[0] >> k[1] >> k[2];     cin >> t[0] >> t[1] >> t[2];     int n;     cin >> n;     for (i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     for (i = 0; i < n; i++) {       b[i].x = a[i];       b[i].idx = i;     }     for (i = 0; i < n; i++) {       if (k[0] > 0) {         b[i].x += t[0];         Q.push(b[i].x);         k[0]--;       } else {         long long x = Q.top();         Q.pop();         b[i].x = max(x, b[i].x) + t[0];         Q.push(b[i].x);       }     }     while (!Q.empty()) Q.pop();     sort(b, b + n);     for (i = 0; i < n; i++) {       if (k[1] > 0) {         b[i].x += t[1];         Q.push(b[i].x);         k[1]--;       } else {         long long x = Q.top();         Q.pop();         b[i].x = max(x, b[i].x) + t[1];         Q.push(b[i].x);       }     }     while (!Q.empty()) Q.pop();     sort(b, b + n);     for (i = 0; i < n; i++) {       if (k[2] > 0) {         b[i].x += t[2];         Q.push(b[i].x);         k[2]--;       } else {         long long x = Q.top();         Q.pop();         b[i].x = max(x, b[i].x) + t[2];         Q.push(b[i].x);       }     }     while (!Q.empty()) Q.pop();     sort(b, b + n);     long long ret = 0;     for (i = 0; i < n; i++) {       if (ret < b[i].x - a[b[i].idx]) ret = b[i].x - a[b[i].idx];     }     cout << ret << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005, MAXM = 1005;   bitset<MAXM> All, P[MAXM];   int n, m, Q;   int start[MAXN], cnt = 0;   int Ans[MAXN];   struct Node {     int op, x, y, id;   } T[MAXN];   struct Edge {     int next, to;   } edge[MAXN];   void add(int from, int to) {     cnt++;     edge[cnt].to = to;     edge[cnt].next = start[from];     start[from] = cnt;     return;   }   void DFS(int x, int from, int Now) {     bool q = 0;     if (T[x].op == 1) {       q = P[T[x].x][T[x].y];       if (P[T[x].x][T[x].y] == 0) Now++;       P[T[x].x][T[x].y] = 1;     }     if (T[x].op == 2) {       q = P[T[x].x][T[x].y];       if (P[T[x].x][T[x].y] == 1) Now--;       P[T[x].x][T[x].y] = 0;     }     if (T[x].op == 3) {       int A = P[T[x].x].count();       P[T[x].x] ^= All;       Now += P[T[x].x].count() - A;     }     Ans[T[x].id] = Now;     for (int i = start[x]; i; i = edge[i].next) {       int to = edge[i].to;       if (to != from) DFS(to, x, Now);     }     if (T[x].op <= 2) P[T[x].x][T[x].y] = q;     if (T[x].op == 3) P[T[x].x] ^= All;     return;   }   inline int read() {     int x = 0, flag = 1;     char ch = getchar();     for (; ch >  9  || ch <  0 ; ch = getchar())       if (ch ==  - ) flag = -1;     for (; ch >=  0  && ch <=  9 ; ch = getchar())       x = (x << 3) + (x << 1) + ch -  0 ;     return x * flag;   }   int main() {     n = read(), m = read(), Q = read();     for (int i = 1; i <= m; i++) All[i] = 1;     for (int i = 1; i <= n; i++) P[i].reset();     T[0].x = T[0].y = 0;     for (int i = 1; i <= Q; i++) {       T[i].op = read();       T[i].id = i;       if (T[i].op <= 2)         T[i].x = read(), T[i].y = read();       else         T[i].x = read();       if (T[i].op <= 3)         add(i - 1, i);       else         add(T[i].x, i);     }     DFS(0, 0, 0);     for (int i = 1; i <= Q; i++) cout << Ans[i] << endl;     return 0;   }