malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T Max(T a, T b) {     return a > b ? a : b;   }   template <typename T>   inline T Min(T a, T b) {     return a < b ? a : b;   }   template <typename T>   inline void checkMax(T &a, T b) {     if (a < b) a = b;   }   template <typename T>   inline void checkMin(T &a, T b) {     if (a > b) a = b;   }   template <typename T>   inline T Abs(T a) {     return a > 0 ? a : -a;   }   int a;   string s;   int num[4005];   int SumR[4005];   int Cnt[50000];   long long ans;   void work() {     cin >> s;     int len = s.length();     for (int i = 0; i < len; i++) {       num[i] = s[i] -  0 ;     }     for (int i = 0; i < len; i++) {       if (i == 0)         SumR[i] = num[i];       else         SumR[i] = SumR[i - 1] + num[i];     }     memset(Cnt, 0, sizeof(Cnt));     for (int i = 0; i < len; i++) {       for (int j = i; j < len; j++) {         int tmp = SumR[j];         if (i != 0) tmp -= SumR[i - 1];         Cnt[tmp]++;       }     }     ans = 0;     for (int i = 0; i < len; i++) {       for (int j = i; j < len; j++) {         int tmp = SumR[j];         if (i != 0) tmp -= SumR[i - 1];         if (tmp != 0) {           if (a % tmp == 0) {             long long div = a / tmp;             if (div <= SumR[len - 1]) {               ans += Cnt[div];             }           }         } else {           if (a == 0) {             ans += len * (len + 1) / 2;           }         }       }     }     cout << ans << endl;   }   int main() {     while (cin >> a) {       work();     }     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;       sort(s.begin(), s.end());       map<char, int> store;       for (int i = 0; i < n; i++) {         store[s[i]]++;       }       if (store.size() == 1) {         int temp = n / k;         if (n % k != 0) temp++;         for (int i = 0; i < temp; i++) cout << s[0];       } else if (store.size() == 2 && store[s[0]] == k) {         cout << s[0];         int temp = n / k;         if (n % k != 0) temp++;         for (int i = 0; i < temp - 1; i++) cout << s[k];       } else {         if (s[0] != s[k - 1])           cout << s[k - 1];         else {           for (int i = k - 1; i < n; i++) cout << s[i];         }       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   set<int> v;   multiset<int> diff;   void clean() {     if (v.size() < 2) {       cout << 0 << endl;       return;     }     cout << *v.rbegin() - *v.begin() - *diff.rbegin() << endl;   }   int main() {     v.clear();     diff.clear();     int n, q;     cin >> n >> q;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       v.insert(x);     }     for (auto it = v.begin(); next(it) != v.end(); it++)       diff.insert(*next(it) - *it);     clean();     while (q--) {       int t, x;       cin >> t >> x;       if (t == 1) {         v.insert(x);         set<int>::iterator it = v.find(x);         if (it == v.begin())           diff.insert(*next(it) - *it);         else if (next(it) == v.end())           diff.insert(*it - *prev(it));         else {           diff.erase(diff.find(*next(it) - *prev(it)));           diff.insert(*next(it) - *it);           diff.insert(*it - *prev(it));         }       } else {         set<int>::iterator it = v.find(x);         if (v.size() >= 2) {           if (it == v.begin())             diff.erase(diff.find(*next(it) - *it));           else if (next(it) == v.end())             diff.erase(diff.find(*it - *prev(it)));           else {             diff.erase(diff.find(*it - *prev(it)));             diff.erase(diff.find(*next(it) - *it));             diff.insert(*next(it) - *prev(it));           }         }         v.erase(it);       }       clean();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int const oo = 1e9, bound = 1e6, mod = oo + 7;   long long const OO = 1e18;   int n, m, k, aa[20];   int cc[20][20];   long long dp[18][1 << 18];   long long rec(int idx, int msk) {     long long &ret = dp[idx][msk];     if (ret != -1) return ret;     int cop = msk, e = 0;     while (cop) {       if (cop & 1) e++;       cop >>= 1;     }     if (e == m) return ret = 0;     for (int(i) = 0; (i) < (n); (i)++) {       if (!((msk >> i) & 1))         ret = max(ret,                   rec(i, (1 << i) | msk) + aa[i] + (msk != 0 ? cc[idx][i] : 0));     }     return ret;   }   int main() {     memset(dp, -1, sizeof dp);     scanf( %d , &n), scanf( %d , &m), scanf( %d , &k);     for (int(i) = 0; (i) < (n); (i)++) scanf( %d , &aa[i]);     for (int(i) = 0; (i) < (k); (i)++) {       int a, b, c;       scanf( %d , &a), scanf( %d , &b), scanf( %d , &c);       a--, b--;       cc[a][b] = c;     }     long long mx = rec(0, 0);     printf( %lld n , mx);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int INF = 98769876987698889LL;   const int MOD = 1e9 + 7;   const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};   const int dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};   const int dx4[] = {1, -1, 0, 0};   const int dy4[] = {0, 0, 1, -1};   const int N = 2e5 + 5;   long long int dp1[N], a[N], f[N], dp2[N], s[N];   int n;   vector<int> G[N];   void dfs(int x, int pa) {     if (G[x].size() == 1 and G[x][0] == pa) {       s[x] = a[x];       return;     }     s[x] = a[x];     for (auto k : G[x]) {       if (k == pa) continue;       dfs(k, x);       s[x] += s[k];     }   }   void dfs2(int x, int pa) {     if (G[x].size() == 1 and G[x][0] == pa) {       f[x] = 0;       return;     }     f[x] = 0;     vector<long long int> v;     for (auto k : G[x]) {       if (k == pa) continue;       dfs2(k, x);       if (s[k] >= dp1[k]) {         v.push_back(s[k]);       } else {         v.push_back(dp1[k]);       }     }     sort(v.begin(), v.end());     dp1[x] = v[v.size() - 1];     if (v.size() > 1) {       f[x] = 1;       dp2[x] = v[v.size() - 2];     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 0; i < N; i++) {       dp1[i] = -INF;       dp2[i] = -INF;     }     for (int i = 2; i <= n; i++) {       int x, y;       cin >> x >> y;       G[x].push_back(y);       G[y].push_back(x);     }     if (n == 1) {       cout <<  Impossible  << endl;       return 0;     }     dfs(1, 0);     dfs2(1, 0);     int fl = 0;     for (int i = 1; i <= n; i++) {       if (f[i]) fl = 1;     }     if (!fl) {       cout <<  Impossible  << endl;       return 0;     }     long long int ans = -INF;     for (int i = 1; i <= n; i++) {       if (f[i]) {         ans = max(ans, dp1[i] + dp2[i]);       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     for (int i = 0; i < t; ++i) {       int n, m, h;       cin >> n >> m;       long long int sum = 0;       for (int j = 0; j < n; ++j) {         int x;         cin >> x;         if (j != 0) sum = sum + x;         if (j == 0) h = x;       }       if (m - h < sum)         h = m;       else         h = h + sum;       cout << h <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   long long n, k, p;   string s;   vector<long long> mem;   long long solve(int i) {     if (mem[i] != -1) return mem[i];     if (i == 0) return 0;     long long tmp = stoll(s.substr(i - 1, 1));     long long res = 1ll << 62;     for (int j = i - 1; tmp < n; --j) {       if (s[j] !=  0  || j == i - 1) {         long long tmptmp = solve(j);         if (tmptmp < ((1ll << 62) - tmp) / n && tmptmp > -1)           res = min(res, tmp + n * tmptmp);       }       if (j - 1 < 0) break;       tmp = stoll(s.substr(j - 1, i - j + 1));     }     mem[i] = res;     return res;   }   int main(int argc, char const *argv[]) {     cin >> n;     cin >> s;     k = s.length();     if (n < 11) {       long long res = 0;       for (int i = 0; i < k; ++i) {         res *= n;         res += stoi(s.substr(i, 1));       }       cout << res << endl;       return 0;     }     mem = vector<long long>(k + 1, -1);     cout << solve(k) << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( unroll-loops )   using namespace std;   const int MX = 2000006;   char a[MX], b[MX];   char arb[MX], abr[MX], ba[MX];   int parb[MX], zabr[MX], zba[MX], pos[MX];   void compute_pi(int n, char s[], int pi[]) {     pi[0] = 0;     for (int i = 1; i < n; i++) {       int j = pi[i - 1];       while (j) {         if (s[j] == s[i]) {           pi[i] = j + 1;           break;         }         j = pi[j - 1];       }       if (j == 0) pi[i] = (s[i] == s[0]) ? 1 : 0;     }   }   void compute_z(int n, char s[], int z[]) {     int l = 0, r = 0;     for (int i = 1; i < n; i++) {       if (i <= r) z[i] = min(z[i - l], r - i + 1);       for (int j = i + z[i], p = z[i]; j < n; j++, p++) {         if (s[p] == s[j])           z[i]++;         else           break;       }       if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;     }   }   void calc(int n, int m) {     compute_pi(n + m + 1, arb, parb);     compute_z(n + m + 1, abr, zabr);     compute_z(n + m + 1, ba, zba);     memset(pos, -1, sizeof(pos));     for (int i = n + 1, p = 0; i <= n + m; i++, p++) {       if (parb[i] < 1) continue;       int j = p - parb[i] + 1;       if (pos[p] == -1) pos[p] = j;     }   }   void make(int n, int m) {     char sep[] =    ;     sep[0] = 31;     strcpy(ba, b);     strcat(ba, sep);     strcat(ba, a);     strcpy(arb, a);     reverse(arb, arb + n);     strcat(arb, sep);     strcat(arb, b);     strcpy(abr, a);     reverse(b, b + m);     strcat(abr, sep);     strcat(abr, b);   }   int main() {     gets(a), gets(b);     int n = strlen(a), m = strlen(b);     make(n, m);     calc(n, m);     int x = -1, y = -1;     for (int i = m + 2; (i <= n + m && n == m); i++) {       int p = pos[n + m - i];       if (p < 0 || p > zba[i]) continue;       if (zabr[n + 1] >= i - m - 1) x = i - m - 2, y = i - m - 1 + p;     }     printf( %d %d n , x, y);     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:64777216 )   using namespace std;   const long long maxn = 100001;   const long long maxk = 200001;   const long long maxx = 10001;   const long long secret_number = 87468267;   const long long inf = 1e18;   const int iinf = 2147483647 / 2;   const double pi = 3.141592653589793238462643383279502884;   const double eps = 1e-7;   const string something_very_long =        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa         aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa         aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa         aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa         aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa         aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa         aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa         aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa         aaaaaaaa ;   const string govno =  g ;   const int maxp = 101;   int n, p, q;   int pr[maxp];   int main() {     cin.sync_with_stdio(0);     cin >> n >> p >> q;     string s;     cin >> s;     for (int i = 0; i < maxp; ++i) pr[i] = -2;     pr[0] = 0;     queue<int> qq;     qq.push(0);     while (!qq.empty()) {       int cur = qq.front();       qq.pop();       if ((cur + p <= s.length()) && (pr[cur + p] == -2))         pr[cur + p] = cur, qq.push(cur + p);       if ((cur + q <= s.length()) && (pr[cur + q] == -2))         pr[cur + q] = cur, qq.push(cur + q);     }     stack<string> v;     int cur = s.length();     if (pr[cur] == -2) {       cout << -1;       return 0;     }     while (true) {       if (cur != 0) {         v.push(s.substr(pr[cur], cur - pr[cur]));         cur = pr[cur];       } else         break;     }     cout << v.size() <<   n ;     while (!v.empty()) {       string aa = v.top();       v.pop();       cout << aa <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   struct p {     ll v;     int i;   } pp[3];   bool cmp(p x, p y) { return x.v < y.v; }   void dd() {     sort(pp, pp + 3, cmp);     ll y = 2 * pp[2].v - pp[0].v - pp[1].v;     cout << y << endl;     cout.flush();     int x;     cin >> x;     if (x == 0) {       return;     } else {       if (pp[0].i == x) {         cout << pp[2].v - pp[1].v << endl;         cout.flush();         int g;         cin >> g;         return;       } else if (pp[1].i == x) {         cout << pp[2].v - pp[0].v << endl;         cout.flush();         int g;         cin >> g;       } else {         pp[2].v += y;         dd();       }     }   }   int main() {     ll a, b, c;     cin >> a >> b >> c;     pp[0].v = a;     pp[0].i = 1;     pp[1].v = b;     pp[1].i = 2;     pp[2].v = c;     pp[2].i = 3;     cout <<  First  << endl;     cout.flush();     dd();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     vector<vector<int>> g(n);     for (int i = 0; (i) < (int)(n - 1); (i)++) {       int a, b;       scanf( %d%d , &a, &b);       a--, b--;       g[a].push_back(b);       g[b].push_back(a);     }     int ans = 0;     for (int s = 0; (s) < (int)(n); (s)++) {       for (int t = s + 1; t < n; t++) {         vector<int> tmp, path;         function<void(int, int)> dfs = [&](int u, int prev) {           if (u == t) {             path = tmp;             return;           }           for (auto v : g[u])             if (v != prev) {               tmp.push_back(v);               dfs(v, u);               tmp.pop_back();             }         };         tmp.push_back(s);         dfs(s, -1);         vector<bool> ng(n);         for (int p : path) ng[p] = true;         int len = (int)path.size() - 1;         vector<int> dp1(n), dp2(n);         function<void(int, int)> dfs2 = [&](int u, int prev) {           vector<int> pro;           for (auto v : g[u])             if (v != prev) {               dfs2(v, u);               dp1[u] = max(dp1[u], dp1[v]);               dp1[u] = max(dp1[u], dp2[v]);               if (!ng[v]) pro.push_back(dp2[v]);             }           if (pro.size() == 0 || ng[u]) return;           sort(pro.rbegin(), pro.rend());           dp2[u] = pro[0] + 1;           if (pro.size() > 1) {             dp1[u] = max(dp1[u], pro[0] + pro[1] + 2);           }         };         dfs2(s, -1);         ans = max(ans, len * dp1[s]);       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   const double pi = acos(-1.0);   int main() {     int n;     double s, f, r, v, t;     scanf( %d %lf %lf , &n, &r, &v);     double p = 2 * pi * r;     double tp = p / v;     while (n--) {       scanf( %lf %lf , &s, &f);       double x = f - s;       double cyc = floor(x / p);       double rem = (x - cyc * p) / r / 2;       double lo = 0, hi = pi;       for (int i = 0; i < 60; ++i) {         double mid = (lo + hi) / 2;         if (mid + sin(mid) < rem)           lo = mid;         else           hi = mid;       }       t = cyc * tp + 2 * lo * r / v;       printf( %.8lf n , t);     }   }
#include <bits/stdc++.h>   using namespace std;   int a[11000][4];   int ans[110][110];   int main() {     cin.sync_with_stdio(false);     cin.tie(0);     int n, m, q;     cin >> n >> m >> q;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) ans[i][j] = 0;     for (int i = 0; i < q; i++) {       int x1;       cin >> x1;       if (x1 != 3) {         int x2;         cin >> x2;         x2--;         a[i][0] = x1;         a[i][1] = x2;         a[i][2] = 0;         a[i][3] = 0;       } else {         int x2, x3, x4;         cin >> x2 >> x3 >> x4;         x2--;         x3--;         a[i][0] = x1;         a[i][1] = x2;         a[i][2] = x3;         a[i][3] = x4;       }     }     for (int i = q - 1; i >= 0; i--) {       if (a[i][0] == 3) {         ans[a[i][1]][a[i][2]] = a[i][3];       }       if (a[i][0] == 1) {         int x = ans[a[i][1]][m - 1];         for (int j = m - 1; j > 0; j--) {           ans[a[i][1]][j] = ans[a[i][1]][j - 1];         }         ans[a[i][1]][0] = x;       }       if (a[i][0] == 2) {         int x = ans[n - 1][a[i][1]];         for (int j = n - 1; j > 0; j--) {           ans[j][a[i][1]] = ans[j - 1][a[i][1]];         }         ans[0][a[i][1]] = x;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) cout << ans[i][j] <<    ;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, arr[110], c1, c0;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , &arr[i]), c1 += arr[i];     int out = 0;     for (int i = 0; i < n; ++i) {       c0 += (!arr[i]);       out = max(out, c0 + c1);       c1 -= arr[i];     }     cout << out;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int a;     int b;     int index;   };   bool compare(node &n1, node &n2) {     if (n1.a < n2.a)       return true;     else       return false;   }   bool compare1(node &n1, node &n2) {     if (n1.b < n2.b)       return true;     else       return false;   }   int main() {     int n;     cin >> n;     vector<node> pq(n);     for (int i = 0; i < n; i++) {       cin >> pq[i].a >> pq[i].b;       pq[i].index = i;     }     int num = 0;     for (int i = 0; i < n; i++) {       if (pq[i].a < pq[i].b) num++;     }     vector<node> track;     if (num >= n / 2) {       for (int i = 0; i < n; i++) {         if (pq[i].a < pq[i].b) track.push_back(pq[i]);       }       sort(track.begin(), track.end(), compare);       cout << track.size() << endl;       for (int i = track.size() - 1; i >= 0; i--) {         cout << track[i].index + 1 <<    ;       }     } else {       for (int i = 0; i < n; i++) {         if (pq[i].a > pq[i].b) track.push_back(pq[i]);       }       sort(track.begin(), track.end(), compare1);       cout << track.size() << endl;       for (int i = 0; i < track.size(); i++) {         cout << track[i].index + 1 <<    ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int hy, ay, dy;     int hm, am, dm;     int h, a, d;     cin >> hy >> ay >> dy;     cin >> hm >> am >> dm;     cin >> h >> a >> d;     int res = 1e9;     for (int atk = dm + 1; atk <= 200; ++atk) {       for (int def = dy; def <= 100; ++def) {         int rnd = (hm + atk - dm - 1) / (atk - dm);         int h_add = max(0, rnd * max(0, am - def) - hy + 1);         int a_add = max(0, atk - ay);         int d_add = max(0, def - dy);         res = min(res, h_add * h + a_add * a + d_add * d);       }     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, br[20][200200], d[20][200200], lev[200200];   vector<int> in, adj[200200], myc[200200], ans;   bool dead[200200];   vector<multiset<int>> m[200200];   multiset<int> sub, best[200200], outofall;   int go(int l, int i, int p = -1) {     in.push_back(i);     for (int j : adj[i])       if (j != p && !dead[j]) {         d[l][i] += go(l, j, i);       }     return ++d[l][i];   }   void dfs(int l, int i, int p) {     for (int j : adj[i])       if (j != p && !dead[j]) {         br[l][j] = br[l][i];         d[l][j] = d[l][i] + 1;         dfs(l, j, i);       }   }   void rec(int l, int i) {     in.clear(), go(l, i);     int C = -1;     for (int k : in) {       int mx = d[l][i] - d[l][k];       for (int j : adj[k])         if (d[l][j] < d[l][k]) {           mx = max(mx, d[l][j]);         }       if (mx <= d[l][i] / 2) {         C = k;         break;       }     }     lev[C] = l;     for (int k : in) {       myc[k].push_back(C);     }     for (int k : in) {       d[l][k] = 0;     }     for (int j : adj[C])       if (!dead[j]) {         sub.clear(), d[l][j] = 1;         br[l][j] = (int)m[C].size();         dfs(l, j, C), m[C].push_back(sub);       }     dead[C] = 1;     for (int j : adj[C])       if (!dead[j]) {         rec(l + 1, j);       }   }   int main() {     scanf( %d , &N);     for (int i = (2); i < (N + 1); i++) {       int p;       scanf( %d , &p);       adj[i].push_back(p), adj[p].push_back(i);     }     rec(0, 1);     for (int i = (1); i < (N + 1); i++) {       for (int c : myc[i]) {         if ((int)best[c].size() >= 2) {           auto it = --best[c].end();           int t = *it + *prev(it);           if (outofall.find(t) != outofall.end()) {             outofall.erase(outofall.find(t));           }         }         if (c == i) {           best[c].insert(0);         } else {           int myb = br[lev[c]][i], myd = d[lev[c]][i];           if (m[c][myb].size() &&               best[c].find(*m[c][myb].rbegin()) != best[c].end()) {             best[c].erase(best[c].find(*m[c][myb].rbegin()));           }           m[c][myb].insert(myd);           while ((int)m[c][myb].size() > 2) m[c][myb].erase(m[c][myb].begin());           best[c].insert(*m[c][myb].rbegin());           while ((int)best[c].size() > 2) best[c].erase(best[c].begin());         }         if ((int)best[c].size() >= 2) {           auto it = --best[c].end();           outofall.insert(*it + *prev(it));           while ((int)outofall.size() > 2) outofall.erase(outofall.begin());         }       }       if (i >= 2) printf( %d  , *outofall.rbegin());     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<pair<long long, long long>, long long> m;   int main() {     long long t, ai, bi, dr = 1;     cin >> t;     vector<pair<long long, long long>> v(t);     for (int i = 0; i < t; i++) {       cin >> ai >> bi;       v[i] = {ai, bi};     }     m[{0, 0}] = 1;     dr += min(v[0].first, v[0].second);     m[{v[0].first, v[0].second}] = 1;     for (int i = 1; i < t; i++) {       if (v[i].first > v[i - 1].first && v[i].second > v[i - 1].second &&           m[{v[i].first, v[i].second}] == 0 &&           min(v[i].first, v[i].second) >= max(v[i - 1].second, v[i - 1].first)) {         if ((v[i - 1].first != 0 || v[i - 1].second != 0) &&             v[i - 1].first != v[i - 1].second) {           dr += min(v[i].first, v[i].second) -                 max(v[i - 1].first, v[i - 1].second) + 1;         } else {           dr +=               min(v[i].first, v[i].second) - max(v[i - 1].first, v[i - 1].second);         }         m[{v[i].first, v[i].second}] = 1;       } else if ((v[i].first > v[i].second && v[i].second == v[i - 1].second &&                   v[i - 1].first < v[i - 1].second) ||                  (v[i].second > v[i].first && v[i].first == v[i - 1].first &&                   v[i - 1].second < v[i - 1].first) &&                      m[{v[i].first, v[i].second}] == 0) {         dr++;         m[{v[i].first, v[i].second}] = 1;       } else if (v[i].first == v[i].second && m[{v[i].first, v[i].second}] == 0) {         dr++;         m[{v[i].first, v[i].second}] = 1;       }     }     cout << dr;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T qmin(const T a, const T b) {     return a < b ? a : b;   }   template <typename T>   inline T qmax(const T a, const T b) {     return a > b ? a : b;   }   template <typename T>   inline void getmin(T &a, const T b) {     if (a > b) a = b;   }   template <typename T>   inline void getmax(T &a, const T b) {     if (a < b) a = b;   }   inline void fileio(string s) {     freopen((s +  .in ).c_str(),  r , stdin);     freopen((s +  .out ).c_str(),  w , stdout);   }   const int inf = 1e9 + 7;   const long long linf = 1e17 + 7;   const int N = 2e5 + 7;   int q[N], st, ed;   int n, deg[N], s[N];   int tot, ans[N][2];   void dfs(int u) {     int v = s[u];     ++tot, ans[tot][0] = u, ans[tot][1] = v;     --deg[v], s[v] ^= u;     --deg[u], s[u] = 0;     if (deg[v] == 1) dfs(v);   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d%d , deg + i, s + i);     }     for (int i = 0; i < n; ++i) {       if (deg[i] == 1) dfs(i);     }     printf( %d n , tot);     for (int i = 1; i <= tot; ++i) printf( %d %d n , ans[i][0], ans[i][1]);     return 0;   }