malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const double pi = 2 * acos(0);   const int oo = 2e9;   const int N = 205;   const int AL = 26;   vector<int> idx[AL];   vector<int> adj[N];   int clr[N];   bool dfs(int u, int c = 0);   int main() {     int n;     scanf( %d , &(n));     string s(n,    );     for (int i = 0; i < n; i++) scanf(  %c , &s[i]);     memset(clr, -1, sizeof(clr));     for (int i = 0; i < n; i++) {       int x = s[i] -  a ;       for (int c = x + 1; c < AL; c++) {         for (auto& j : idx[c]) {           adj[i].push_back(j);           adj[j].push_back(i);         }       }       idx[x].push_back(i);     }     bool valid = true;     for (int i = 0; i < n; i++) {       if (clr[i] == -1) valid &= dfs(i);     }     if (valid) {       puts( YES );       for (int i = 0; i < n; i++) {         printf( %d , clr[i]);       }       printf(  n );     } else       printf( NO n );     return 0;   }   bool dfs(int u, int c) {     clr[u] = c;     bool ret = true;     for (auto& v : adj[u]) {       if (clr[v] == -1)         ret &= dfs(v, !c);       else if (c == clr[v])         return false;     }     return ret;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5;   long long int rev[N], fac[N], mod = 1e9 + 7;   long long int wop(long long int x, long long int y) {     if (y == 0) return 1;     long long int ret = wop(x, y / 2);     ret %= mod;     ret *= ret;     ret %= mod;     if (y & 1) ret *= x;     ret %= mod;     return ret;   }   long long int chos(long long int r, long long int n) {     return (fac[n] * ((rev[r] * rev[n - r]) % mod)) % mod;   }   int main() {     long long int n, m;     cin >> n >> m;     rev[0] = fac[0] = 1;     for (int i = 1; i < 2e3; i++) {       fac[i] = fac[i - 1] * i;       fac[i] %= mod;       rev[i] = wop(fac[i], mod - 2);     }     long long int ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = i; j <= n; j++) {         long long int f1 = chos(i - 1, i + m - 2);         long long int f2 = chos(n - j, n + m - j - 1);         ans += (f1 * f2) % mod;         ans %= mod;       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int euclid(int a, int b, int &x, int &y) {     if (!a) {       x = 0;       y = 1;       return b;     }     int _x, _y;     int g = euclid(b % a, a, _x, _y);     x = _y - b / a * _x;     y = _x;     return g;   }   void relax(int &obj, int C3, int C4, int C5, int _k3, int k4, int _k5, int &K3,              int &K4, int &K5) {     int f = abs(C3 * _k3 - C4 * k4) + abs(C4 * k4 - C5 * _k5);     if (f < obj) {       obj = f;       K3 = _k3, K4 = k4, K5 = _k5;     }   }   int main() {     int n, S, a[333];     cin >> n >> S;     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     int C[11] = {0};     for (int _n(n), i(0); i < _n; i++) C[a[i]]++;     int K3 = 1011111111, K4 = 1011111111, K5 = 1011111111, F = 1011111111;     int ek3 = 1011111111, ek5 = 1011111111;     const int D = euclid(C[3], C[5], ek3, ek5);     for (int k4 = 0; k4 * C[4] <= S; ++k4) {       const int REM = S - k4 * C[4];       if (REM % D) continue;       int k3 = ek3 * (REM / D), k5 = ek5 * (REM / D);       assert(k3 * C[3] + k5 * C[5] == REM);       int idx[] = {(k4 - k3 + C[5] / D - 1) / (C[5] / D),                    (k5 - k4 + C[3] / D - 1) / (C[3] / D),                    (k5 - k4 * C[4] / C[5] + C[3] / D - 1) / (C[3] / D) + 2,                    (k4 * C[4] / C[3] - k3 + C[5] / D - 1) / (C[5] / D) + 2};       for (int o = 0; o < 4; ++o) {         int j = idx[o];         for (int it = 0; it < 5; --j, ++it) {           int _k3 = k3 + j * (C[5] / D);           int _k5 = k5 - j * (C[3] / D);           if (_k3 < 0) continue;           if (_k3 > k4) continue;           if (_k5 < k4) continue;           relax(F, C[3], C[4], C[5], _k3, k4, _k5, K3, K4, K5);         }       }     }     if (F == 1011111111) {       cout << -1 << endl;     } else {       printf( %d %d %d n , K3, K4, K5);     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( tune=native )   using namespace std;   const int MAX = 1e6 + 5;   const long long MOD = 1000000007;   const long long MOD2 = 2010405347;   const long long INF = 2e18;   const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0};   const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1, 0};   const double pi = acos(-1);   const double EPS = 1e-9;   const int block = 315;   inline long long pw(long long x, long long y, long long md = MOD) {     long long ret = 1;     while (y) {       if (y & 1) ret = ret * x % md;       x = x * x % md, y >>= 1;     }     return ret;   }   int n, x[MAX], y[MAX], z[MAX], nw;   long long ans;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = (1); i <= (n); ++i) {       cin >> x[i];       y[i] = max(y[i - 1], x[i] + 1);     }     for (int i = (n); i >= (1); --i) {       nw = max(nw - 1, x[i] + 1);       z[i] = nw;     }     for (int i = (1); i <= (n); ++i) {       nw = max(y[i], z[i]);       ans += nw - x[i] - 1;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void chkmax(T& x, T y) {     if (x < y) x = y;   }   template <typename T>   void chkmin(T& x, T y) {     if (x > y) x = y;   }   inline int read() {     int x = 0;     char c = getchar();     bool f = 0;     while (c < 48) f |= c ==  - , c = getchar();     while (c > 47) x = x * 10 + (c ^ 48), c = getchar();     return f ? -x : x;   }   int N, p[114];   long long getv(long long x) {     long long res = 0;     for (int i = (N - 1), iend = (0); i >= iend; --i) {       if ((long double)res * x + p[i] > 1e18) return -1;       res = res * x + p[i];     }     return res;   }   void solve() {     long long t, a, b;     cin >> t >> a >> b;     int res = a == b ? 1 : 0, tt = -1, ct = 0;     if (t > a || a > b || (t == a && a == 1 && b > 1))       return printf( %d n , res), void();     if (b == 1) return puts( inf ), void();     if (a != 1) {       for (long long tp = b; tp; tp /= a) p[N++] = tp % a, ct += tp % a != 0;       res += getv(t) == a && getv(a) == b;       if (ct == 1) tt = N - 1;     }     long long zzh = 1, yyh = 1;     for (int i = (1), iend = (60); i <= iend; ++i) {       if ((long double)yyh * a > 1e18) break;       zzh *= t, yyh *= a;       if (i != tt && a % zzh == 0 && b % yyh == 0 && a / zzh == b / yyh) res++;     }     cout << res << endl;   }   signed main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long MOD = 1000000007;   long long dp[2001][2001];   long long dp1[2001][2001];   int main() {     int N, K;     string S;     cin >> N >> K >> S;     memset(dp, 0, sizeof(dp));     memset(dp1, 0, sizeof(dp1));     dp[0][0] = dp1[0][0] = 1;     for (int n = 1; n <= N; ++n) {       for (int k = 0; k <= K; ++k) {         dp[n][k] = dp1[n - 1][k] * (long long)(S[n - 1] -  a ) % MOD;       }       for (int i = 0; i < n; ++i) {         int delta = (n - i) * (N - n + 1);         for (int k = 0; k + delta <= K; ++k) {           dp[n][k + delta] += dp[i][k] * (long long)( z  - S[n - 1]) % MOD;           dp[n][k + delta] %= MOD;         }       }       for (int k = 0; k <= K; ++k) {         dp1[n][k] = (dp1[n - 1][k] + dp[n][k]) % MOD;       }     }     cout << dp1[N][K] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5;   int type[N], n, p[N], out[N];   int go(int u, bool print = false) {     int res = p[u] == -1 || out[p[u]] > 1 ? 1 : go(p[u], print) + 1;     if (print) cout << u + 1 <<    ;     return res;   }   int main() {     cin >> n;     for (int i = 0; i < n; ++i) cin >> type[i];     for (int i = 0; i < n; ++i) {       cin >> p[i];       if (--p[i] >= 0) ++out[p[i]];     }     int res = -1;     for (int i = 0; i < n; ++i)       if (type[i] == 1)         if (res == -1 || go(i) > go(res)) res = i;     cout << go(res) << endl;     go(res, true);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   const int MAXN = 1e5 + 5;   using namespace std;   struct node {     int i;     node *l, *r;   };   node *newN(int i) {     node *x = new node;     x->i = i;     x->r = x->l = NULL;     return x;   }   node *insert(node *actual, int i, bool k) {     if (!actual) return newN(i);     if (k)       return actual->r = newN(i);     else       return actual->l = newN(i);   }   void inorder(node *root) {     if (!root) return;     inorder(root->l);     cout << root->i <<   n ;     inorder(root->r);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     string a;     cin >> a;     node *root = newN(1), *actual = root;     for (int i = 0; i < (int)a.size() - 1; i++) {       if (a[i] ==  l )         actual = insert(actual, i + 2, 0);       else         actual = insert(actual, i + 2, 1);     }     inorder(root);     return 0;   }
#include <bits/stdc++.h>   const double eps = 1e-10;   const float epsf = 1e-6;   using namespace std;   inline long long int __gcd(long long int a, long long int b) {     if (a == 0 || b == 0) {       return max(a, b);     }     long long int tempa, tempb;     while (1) {       if (a % b == 0)         return b;       else {         tempa = a;         tempb = b;         a = tempb;         b = tempa % tempb;       }     }   }   inline int compfloat(float& x, float& y) {     if (fabs(x - y) < epsf)       return 0;     else if (x - y > 0)       return 1;     return -1;   }   inline int compdouble(double x, double y) {     if (fabs(x - y) < eps)       return 0;     else if (x - y > 0)       return 1;     else       return -1;   }   bool prime(long long int k) {     for (long long int i = 2; i * i <= k; i++)       if (k % i == 0) {         return false;       }     return true;   }   void pdash(int n = 1) {     for (int i = 0; i < n; i++) {       for (int j = 0; j < 30; j++) {         cout <<  - ;       }       cout <<   n ;     }   }   void solve() {     long long int n;     cin >> n;     long long int arr[n];     for (int i = 0; i < n; i++) cin >> arr[i];     long long int dpi[n], dpd[n];     dpi[0] = 0;     dpd[n - 1] = 0;     for (int i = 1; i < n; i++)       dpi[i] = max(dpi[i - 1] + arr[i - 1] + 1 - arr[i], (long long int)0);     for (int i = (int)n - 2; i >= 0; i--)       dpd[i] = max(dpd[i + 1] + arr[i + 1] + 1 - arr[i], (long long int)0);     long long int sumi[n], sumd[n];     sumi[0] = dpi[0];     sumd[n - 1] = dpd[n - 1];     for (int i = 1; i < n; i++) sumi[i] = sumi[i - 1] + dpi[i];     for (int i = (int)n - 2; i >= 0; i--) sumd[i] = sumd[i + 1] + dpd[i];     long long int ans = numeric_limits<long long int>::max();     for (int i = 1; i < n - 1; i++)       ans = min(ans, sumi[i - 1] + sumd[i + 1] + max(dpi[i], dpd[i]));     ans = min({sumd[0], sumi[n - 1], ans});     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 10;   long long arr[MAX], arr2[MAX];   int n, m;   bool check(long long mid) {     int prv = 0;     for (int i = 0; i < n; ++i) {       while (prv < m && arr2[prv] + mid < arr[i]) ++prv;       if (prv == m || arr2[prv] - mid > arr[i]) return 0;     }     return 1;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 0; i < n; ++i) cin >> arr[i];     for (int i = 0; i < m; ++i) cin >> arr2[i];     sort(arr, arr + n);     sort(arr2, arr2 + m);     long long l = 0, r = 2e9;     long long ans = r;     while (l <= r) {       long long mid = (l + r) >> 1;       if (check(mid))         ans = mid, r = mid - 1;       else         l = mid + 1;     }     return cout << ans <<   n , 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 2;   int a[maxn << 1];   long long vis[maxn];   int main(void) {     std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     int n, m;     while (cin >> n >> m) {       int k = 0;       int t;       vector<int> a(n + m + 1);       vector<long long> vis(m);       for (int i = 1; i <= n + m; i++) cin >> a[i];       for (int i = 1; i <= n + m; i++) cin >> t, t ? vis[k++] = a[i] : 1;       vis[k] = (int)1e18;       for (int i = 1, j = 0; i <= n + m; j++) {         int cnt = 0;         while (a[i] < vis[j]) cnt++, i++;         i++;         while (a[i] - vis[j] <= vis[j + 1] - a[i] && i <= n + m) cnt++, i++;         cout << cnt <<    ;       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   bool isprime[N] = {1, 1, 0};   int sum[N] = {};   void YesIcan() {     for (int i = 2; i * i <= N; ++i) {       for (int j = i * i; j <= N; j += i) isprime[j] = true;     }   }   int main() {     YesIcan();     int a, b, k;     cin >> a >> b >> k;     for (int i = a; i <= b; ++i) {       sum[i] = sum[i - 1];       if (!isprime[i]) ++sum[i];     }     if (sum[b] < k) {       cout << -1;       return 0;     }     int i = a - 1, l = 1;     for (; i <= b - l; ++i) {       while (sum[i + l] - sum[i] < k && l <= b - a + 1 && i + l <= b) ++l;     }     cout << l;   }
#include <bits/stdc++.h>   using namespace std;   int main() {   #ifdef LOCAL     freopen( ../IO/d.in ,  r , stdin);   //  freopen( ../IO/d.out ,  w , stdout);   #else     std::ios_base::sync_with_stdio(false);     std::cin.tie(nullptr);     std::cout.tie(nullptr);   #endif     int number_of_tests;     cin >> number_of_tests;        while (number_of_tests--) {       int n;       cin >> n;       std::vector<int> b(n);       std::vector<int> used(2 * n);       for (int &i : b) cin >> i, --i, used[i] = 1;       std::vector<int> unused;       unused.reserve(n);       for (int i = 0; i < 2 * n; ++i) {         if (!used[i]) unused.push_back(i);       }       vector<int> c(n + 1, true);       int l = -1, r = -1;       auto check1 = [&](int x) {         deque<int> dq(unused.begin(), unused.end());         bool ok = true;         for (int i = x - 1; i >= 0; --i) {           ok &= b[i] < dq.back();           dq.pop_back();         }         return ok;       };       auto check2 = [&](int x) {         deque<int> dq(unused.begin(), unused.end());         bool ok = true;         for (int i = x; i < n; ++i) {           ok &= b[i] > dq.front();           dq.pop_front();         }         return ok;       };       int lo = -1, hi = n + 1;       while (hi - lo > 1) {         int x = (lo + hi) / 2;         if (check1(x)) {           lo = x;         } else {           hi = x;         }       }       l = 0, r = lo;       lo = -1, hi = n + 1;       while (hi - lo > 1) {         int x = (lo + hi) / 2;         if (check2(x)) {           hi = x;         } else {           lo = x;         }       }       l = std::max(l, hi);   //    std::cout << l <<     << r <<   n ;       std::cout << std::max(0, r - l + 1) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   int gcd(int a, int b) {     if (b == 0) return a;     gcd(b, a % b);   }   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int q;     cin >> q;     while (q--) {       int a, b;       cin >> a >> b;       if (gcd(a, b) != 1)         cout <<  INFINITE  << endl;       else         cout <<  FINITE  << endl;     }   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16000000 )   using namespace std;   const int Maxn = 1000005;   const int Maxm = 4194304;   const int Inf = 1000000000;   int n, c;   pair<int, int> lef[Maxn], rig[Maxn];   int me[Maxn];   int res[Maxn], rlen;   int st[Maxm];   void Insert(int v, int l, int r, int x, int val) {     if (l == r)       st[v] = val;     else {       int m = l + r >> 1;       if (x <= m)         Insert(2 * v, l, m, x, val);       else         Insert(2 * v + 1, m + 1, r, x, val);       st[v] = max(st[2 * v], st[2 * v + 1]);     }   }   int Get(int v, int l, int r, int a, int b) {     if (l == a && r == b)       return st[v];     else {       int res = -Inf;       int m = l + r >> 1;       if (a <= m) res = max(res, Get(2 * v, l, m, a, min(m, b)));       if (m + 1 <= b) res = max(res, Get(2 * v + 1, m + 1, r, max(m + 1, a), b));       return res;     }   }   bool isNull(const pair<int, int> &p) { return p == pair<int, int>(Inf, -Inf); }   void Print(int l, int r) {     if (l > r) return;     if (l == r)       res[rlen++] = l;     else {       int from = l + 1;       if (!isNull(lef[l])) {         Print(l + 1, lef[l].second);         from = lef[l].second + 1;       }       res[rlen++] = l;       Print(from, r);     }   }   int main() {     scanf( %d %d , &n, &c);     for (int i = 1; i <= n; i++) {       lef[i] = pair<int, int>(Inf, -Inf);       rig[i] = pair<int, int>(Inf, -Inf);     }     int a, b;     char s[10];     while (c--) {       scanf( %d %d %s , &a, &b, s);       if (s[0] ==  L ) {         lef[a].first = min(lef[a].first, b);         lef[a].second = max(lef[a].second, b);       } else {         rig[a].first = min(rig[a].first, b);         rig[a].second = max(rig[a].second, b);       }     }     for (int i = n; i >= 1; i--) {       if (isNull(lef[i]) && isNull(rig[i]))         me[i] = i;       else if (isNull(lef[i]))         if (rig[i].first <= i) {           printf( IMPOSSIBLE n );           return 0;         } else           me[i] = Get(1, 1, n, i + 1, rig[i].second);       else if (isNull(rig[i]))         if (lef[i].first <= i) {           printf( IMPOSSIBLE n );           return 0;         } else {           lef[i].second = Get(1, 1, n, i + 1, lef[i].second);           me[i] = lef[i].second;         }       else if (lef[i].first <= i) {         printf( IMPOSSIBLE n );         return 0;       } else {         lef[i].second = Get(1, 1, n, i + 1, lef[i].second);         if (lef[i].second >= rig[i].first) {           printf( IMPOSSIBLE n );           return 0;         } else           me[i] = Get(1, 1, n, lef[i].second + 1, rig[i].second);       }       Insert(1, 1, n, i, me[i]);     }     Print(1, n);     for (int i = 0; i < rlen; i++)       printf( %d%c , res[i], i + 1 < rlen ?     :   n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int sz = 7e5;   long long int sum[sz];   long long int mi[sz];   long long int arr[sz];   void build(long long int node, long long int l, long long int r) {     if (l == r) {       sum[node] = arr[l];     } else {       long long int mid = (l + r) / 2;       build(2 * node, l, mid);       build(2 * node + 1, mid + 1, r);       sum[node] = sum[node * 2] + sum[node * 2 + 1];     }   }   long long int query(long long int node, long long int l, long long int r,                       long long int tl, long long int tr) {     if (l > tr || r < tl)       return 0;     else if (l >= tl && r <= tr)       return sum[node];     else       return (query(node * 2, l, (l + r) / 2, tl, tr) +               query(node * 2 + 1, (l + r) / 2 + 1, r, tl, tr));   }   void build2(long long int node, long long int l, long long int r) {     if (l == r) {       mi[node] = arr[l];     } else {       long long int mid = (l + r) / 2;       build2(2 * node, l, mid);       build2(2 * node + 1, mid + 1, r);       mi[node] = min(mi[node * 2], mi[node * 2 + 1]);     }   }   long long int query2(long long int node, long long int l, long long int r,                        long long int tl, long long int tr) {     if (l > tr || r < tl)       return 0;     else if (l >= tl && r <= tr)       return mi[node];     else       return min(query2(node * 2, l, (l + r) / 2, tl, tr),                  query2(node * 2 + 1, (l + r) / 2 + 1, r, tl, tr));   }   long long int pre[sz];   int main() {     std::ios::sync_with_stdio(false);     long long int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> arr[i];     build(1, 1, n);     build2(1, 1, n);     sort(arr, arr + n + 1);     for (int i = 1; i <= n; i++) {       pre[i] = pre[i - 1] + arr[i];     }     long long int q;     cin >> q;     while (q--) {       long long int t;       cin >> t;       if (t == 1) {         long long int l, r;         cin >> l >> r;         cout << query(1, 1, n, l, r) << endl;       } else {         long long int l, r;         cin >> l >> r;         cout << pre[r] - pre[l - 1] << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000,1024000000 )   using namespace std;   const int inf = 0x3f3f3f3f;   const long long INF = 1e18;   template <typename T>   void read(T &x) {     x = 0;     int s = 1, c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) s = -1;     for (; isdigit(c); c = getchar()) x = x * 10 + c - 48;     x *= s;   }   template <typename T>   void write(T x) {     if (x < 0) x = -x, putchar( - );     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   template <typename T>   void writeln(T x) {     write(x);     puts(  );   }   const int maxn = 1e5 + 5, maxm = 1e6 + 5;   struct Edge {     int u, v, c, id;     bool operator<(const Edge &rhs) const { return c < rhs.c; }   } e[maxm];   int n, m;   int fa[maxn];   vector<pair<int, int> > adj[maxn];   int f[maxn][20], dis[maxn][20], d[maxn];   vector<Edge> v;   int find(int v) { return v == fa[v] ? v : fa[v] = find(fa[v]); }   void dfs(int u, int fa) {     d[u] = d[fa] + 1;     for (pair<int, int> x : adj[u])       if (x.first ^ fa) {         int v = x.first, c = x.second;         f[v][0] = u;         dis[v][0] = c;         dfs(v, u);       }   }   int LCA(int x, int y, int op) {     int res = 0;     if (d[x] > d[y]) swap(x, y);     for (int t = 19; t >= 0; t--)       if (d[x] <= d[f[y][t]]) {         res = max(res, dis[y][t]);         y = f[y][t];       }     if (x == y) return op ? res : x;     for (int t = 19; t >= 0; t--)       if (f[x][t] != f[y][t]) {         res = max(res, max(dis[x][t], dis[y][t]));         x = f[x][t], y = f[y][t];       }     res = max(res, max(dis[x][0], dis[y][0]));     return op ? res : f[x][0];   }   int main() {     read(n), read(m);     for (int i = 1; i <= m; i++) {       read(e[i].u), read(e[i].v), read(e[i].c);       e[i].id = i;     }     sort(e + 1, e + 1 + m);     for (int i = 1; i <= n; i++) fa[i] = i;     for (int i = 1; i <= m; i++) {       int p = find(e[i].u), t = find(e[i].v);       if (p != t) {         adj[e[i].u].emplace_back(e[i].v, e[i].c);         adj[e[i].v].emplace_back(e[i].u, e[i].c);         fa[p] = t;       } else         v.emplace_back(e[i]);     }     dfs(1, 0);     for (int j = 1; j <= 19; j++)       for (int i = 1; i <= n; i++) {         f[i][j] = f[f[i][j - 1]][j - 1];         dis[i][j] = max(dis[i][j - 1], dis[f[i][j - 1]][j - 1]);       }     sort((v.begin()), (v.end()), [&](Edge x, Edge y) { return x.id < y.id; });     for (auto i : v) {       int lca = LCA(i.u, i.v, 0);       printf( %d n , max(LCA(i.u, lca, 1), LCA(i.v, lca, 1)));     }   }
#include <bits/stdc++.h>   const size_t max_vertices = 1 << 16;   int degree[max_vertices], xor_sum[max_vertices];   std::queue<int> queue;   std::vector<std::pair<int, int>> result;   int main() {     int vcount = 0;     std::cin >> vcount;     for (int i = 0; i < vcount; i++) {       std::cin >> degree[i] >> xor_sum[i];       if (degree[i] == 1) {         queue.push(i);       }     }     while (!queue.empty()) {       int cur = queue.front();       queue.pop();       int next = xor_sum[cur];       if (degree[cur] > 0 && degree[next] > 0) {         result.push_back(std::make_pair(cur, next));         degree[next]--;         degree[cur]--;         xor_sum[next] ^= cur;       }       if (degree[next] == 1) {         queue.push(next);       }     }     std::cout << result.size() << std::endl;     for (int i = 0; i < result.size(); i++) {       std::cout << result[i].first <<     << result[i].second << std::endl;     }     return 0;   }