malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long n, q;   string s;   int main() {     cin >> n >> q;     while (q--) {       vector<pair<long long, long long> > v;       long long x, l = 1, r = n, cur = n / 2 + 1;       cin >> x >> s;       while (cur != x) {         v.push_back({l, r});         if (x < cur) {           r = cur - 1;           cur = (l + r) / 2;         } else {           l = cur + 1;           cur = (l + r) / 2;         }       }       for (int i = 0; i < s.size(); i++) {         if (s[i] ==  U ) {           if (!v.empty()) {             l = v.back().first, r = v.back().second;             cur = (l + r) / 2;             v.pop_back();           }         }         if (s[i] ==  L ) {           if (l != r) {             v.push_back({l, r});             r = cur - 1;             cur = (l + r) / 2;           }         }         if (s[i] ==  R ) {           if (l != r) {             v.push_back({l, r});             l = cur + 1;             cur = (l + r) / 2;           }         }       }       cout << cur << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   void solve(void);   int main() {     {       ios_base::sync_with_stdio(false);       cin.tie(NULL);       { solve(); }     }     return 0;   }   void solve() {     long long int n, i;     cin >> n;     vector<long long int> v;     for (i = 1; i * i <= n; i++) {       if (n % i == 0) {         v.push_back(i);         if (i != n / i) v.push_back(n / i);       }     }     sort(v.rbegin(), v.rend());     for (auto x : v) {       long long int len = n / x;       long long int a1 = 1;       long long int aend = 1 + (len - 1) * x;       cout << (len * (a1 + aend)) / 2 <<    ;     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   enum { UP, DOWN, LEFT, RIGHT };   const int MAX = 15500;   struct Node {     int dir;     Node* pt[4];   } node[MAX], *cur, *row[MAX], *col[MAX], *st[MAX];   char s[MAX];   int r, c, top;   int getDir(char c) {     switch (c) {       case  U :         return UP;       case  D :         return DOWN;       case  L :         return LEFT;       case  R :         return RIGHT;     }     return -1;   }   void init() {     cur = node;     top = 0;     for (int i = 0; i < r; i++) {       row[i] = cur++;       row[i]->pt[LEFT] = row[i]->pt[RIGHT] = row[i];       row[i]->pt[UP] = row[i]->pt[DOWN] = NULL;       row[i]->dir = -1;     }     for (int i = 0; i < c; i++) {       col[i] = cur++;       col[i]->pt[UP] = col[i]->pt[DOWN] = col[i];       col[i]->pt[LEFT] = col[i]->pt[RIGHT] = NULL;       col[i]->dir = -1;     }   }   Node* add(int x, int y, int dir) {     cur->pt[RIGHT] = row[x]->pt[RIGHT];     cur->pt[LEFT] = row[x];     cur->pt[DOWN] = col[y]->pt[DOWN];     cur->pt[UP] = col[y];     cur->pt[LEFT]->pt[RIGHT] = cur;     cur->pt[RIGHT]->pt[LEFT] = cur;     cur->pt[UP]->pt[DOWN] = cur;     cur->pt[DOWN]->pt[UP] = cur;     cur->dir = dir;     return cur++;   }   int dfs(Node* t) {     if (t->dir == -1) return 0;     t->pt[LEFT]->pt[RIGHT] = t->pt[RIGHT];     t->pt[RIGHT]->pt[LEFT] = t->pt[LEFT];     t->pt[UP]->pt[DOWN] = t->pt[DOWN];     t->pt[DOWN]->pt[UP] = t->pt[UP];     int ret = dfs(t->pt[t->dir]) + 1;     t->pt[LEFT]->pt[RIGHT] = t;     t->pt[RIGHT]->pt[LEFT] = t;     t->pt[UP]->pt[DOWN] = t;     t->pt[DOWN]->pt[UP] = t;     return ret;   }   int main() {     int ret, cnt;     while (scanf( %d%d , &r, &c) == 2) {       ret = -1;       cnt = 0;       init();       for (int i = 0; i < r; i++) {         scanf( %s , &s[i * c]);       }       for (int i = r - 1; i >= 0; i--) {         for (int j = c - 1; j >= 0; j--) {           if (s[i * c + j] !=  . ) st[top++] = add(i, j, getDir(s[i * c + j]));         }       }       for (int i = 0; i < top; i++) {         int sub = dfs(st[i]);         if (sub > ret) {           ret = sub;           cnt = 1;         } else if (sub == ret) {           cnt++;         }       }       printf( %d %d n , ret, cnt);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int i, j, ans = 1, val[256], v;     string s, p;     cin >> s;     char a;     for (a =  0 ; a <=  9 ; a++) {       p.push_back(a);     }     for (a =  A ; a <=  Z ; a++) {       p.push_back(a);     }     for (a =  a ; a <=  z ; a++) {       p.push_back(a);     }     p.push_back( - );     p.push_back( _ );     for (i = 0; i <= 63; ++i) {       val[p[i]] = i;     }     for (i = 0; i < s.length(); ++i) {       v = val[s[i]];       for (j = 0; j < 6; ++j) {         if ((v & (1 << j)) == 0) {           ans = (ans * 3) % 1000000007;         }       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ii = pair<int, int>;   int z[][2] = {{-1, 0}, {1, 0}};   vector<ii> solve(int x, int y) {     if (x < y) swap(x, y);     vector<ii> a;     x -= y - 1;     for (int k = 0; k < 2 * y - 1; ++k) {       a.push_back({2, 3 + k});       if (~k & 1)         for (int j = 0; j < 2 && x > 0; ++j, --x)           a.push_back({2 + z[j][0], 3 + k + z[j][1]});     }     if (x-- > 0) a.push_back({2, 2});     if (x > 0) a.push_back({2, 4 + 2 * (y - 1)});     return a;   }   signed main() {     ios_base ::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int b, w;       cin >> b >> w;       if (max(w, b) > 3 * min(w, b) + 1) {         cout <<  NO n ;         continue;       }       cout <<  YES n ;       auto a = solve(w, b);       if (b > w)         for (auto& [x, y] : a) --y;       for (auto [x, y] : a) cout << x <<     << y <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   bool chmax(T &a, const T &b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <class T>   bool chmin(T &a, const T &b) {     if (b < a) {       a = b;       return 1;     }     return 0;   }   signed main() {     cin.tie(0);     ios::sync_with_stdio(false);     long long N, K;     cin >> N >> K;     vector<long long> A(N), sum(N + 1, 0);     long long ans = 0;     for (long long i = 0; i < N; i++) {       cin >> A[i];       ans += A[i];       sum[i + 1] += sum[i] + A[i];     }     vector<long long> tmp;     for (long long i = (1); i <= (N - 1); ++i) {       tmp.push_back(sum[N] - sum[i]);     }     sort((tmp).rbegin(), (tmp).rend());     for (long long i = 0; i < K - 1; i++) ans += tmp[i];     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, sum = 0;     string s;     cin >> n >> s;     for (int i = 0; i < n; i++) sum += s[i] -  0 ;     for (int i = 2; i <= n; i++) {       if (sum % i == 0) {         int cur = 0;         bool flag = 1;         for (int j = 0; j < n; j++) {           cur += s[j] -  0 ;           if (sum / i < cur) {             flag = 0;             break;           }           if (sum / i == cur) cur = 0;         }         if (flag) {           cout <<  YES ;           return 0;         }       }     }     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, x;   long long f[200010];   vector<pair<int, long long> > ke[200010];   struct te {     int l, r;     long long s;   } a[200010];   bool cmp(te i, te j) { return ((i.l < j.l) || (i.l == j.l && i.r < j.r)); }   int main() {     if (fopen( a.txt ,  r )) {       freopen( a.txt ,  r , stdin);     } else       ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> x;     for (int i = 1; i <= n; i++) cin >> a[i].l >> a[i].r >> a[i].s;     sort(a + 1, a + n + 1, cmp);     int cur = 0;     for (int i = 0; i <= x; i++) f[i] = (1LL << 61);     long long res = (1LL << 61);     for (int i = 1; i <= n; i++) {       while (cur < a[i].l - 1) {         cur++;         for (auto tmp : ke[cur]) {           f[tmp.first] = min(f[tmp.first], tmp.second);         }       }       if (x > a[i].r - a[i].l + 1)         res = min(res, a[i].s + f[x - a[i].r + a[i].l - 1]);       ke[a[i].r].push_back(make_pair(a[i].r - a[i].l + 1, a[i].s));     }     if (res >= (1LL << 61)) res = -1;     cout << res;   }
#include <bits/stdc++.h>   using namespace std;   void fastio() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << fixed;   }   int main() {     fastio();     int n;     cin >> n;     long long int a[n];     long long int totsum = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       totsum += a[i];     }     int m = n - 1;     m >>= 1;     long long int cursum = 0;     for (int i = 0; i < m; i++) cursum += a[2 * i];     long long int maxsum = totsum - cursum;     int last = 0;     int first = 2 * m - 2;     for (int i = 0; i < n; i++) {       cursum -= a[last];       last += 2;       last %= n;       first += 2;       first %= n;       cursum += a[first];       maxsum = max(maxsum, totsum - cursum);     }     cout << maxsum <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ii = pair<int, int>;   using i3 = pair<int, ii>;   using li = pair<ll, int>;   using lii = pair<ll, ii>;   using pll = pair<ll, ll>;   using vi = vector<int>;   using vl = vector<ll>;   using vii = vector<ii>;   using vli = vector<li>;   using vpll = vector<pll>;   using vi3 = vector<i3>;   using vlii = vector<lii>;   const int N = 2e5 + 5, L = 20;   const ll INF = 1e17 + 7, mod = 1e9 + 7;   const double eps = 1e-9, PI = acos(-1);   int n, m;   vector<ii> adj[N];   vector<int> tree[N];   int down[N], level[N];   int cycleId[N];   int to[N][L];   int dep[N];   int cact[N];   void dfs(int u, int p) {     cycleId[u] = u;     level[u] = 1 + level[p];     for (ii A : adj[u]) {       int v = A.second;       int e = A.first;       if (cycleId[v] == 0) {         dfs(v, u);       } else if (v != p) {         if (level[v] < level[u])           cycleId[u] = e;         else           down[u]++;       }     }     for (ii A : adj[u]) {       int v = A.second;       if (v == p) continue;       if ((cycleId[v] != v) && (down[v] == 0)) {         cycleId[u] = cycleId[v];       }     }   }   void dfsTree(int u, int p) {     to[u][0] = p;     dep[u] = 1 + dep[p];     for (int i = 1; i < L; i++) {       to[u][i] = to[to[u][i - 1]][i - 1];     }     for (int v : tree[u]) {       if (v != p) {         cact[v] += cact[u];         dfsTree(v, u);       }     }   }   int jump(int u, int k) {     for (int i = 0; i < L; i++)       if (k & (1 << i)) u = to[u][i];     return u;   }   int LCA(int u, int v) {     if (u == v) return u;     if (dep[u] < dep[v]) swap(u, v);     u = jump(u, dep[u] - dep[v]);     if (u == v) return u;     for (int i = L - 1; i >= 0; i--) {       if (to[u][i] != to[v][i]) {         u = to[u][i];         v = to[v][i];       }     }     return to[u][0];   }   ll pow_mod(ll a, ll b) {     ll ret = 1ll;     a %= mod;     for (; b; ret = ret * (b & 1 ? a : 1ll) % mod, a = a * a % mod, b >>= 1ll)       ;     return ret;   }   ll calc(int u, int v) {     ll A = cact[u];     ll B = cact[v];     int lca = LCA(u, v);     ll C = cact[lca];     return pow_mod(2, A + B - 2 * C + (lca > n));   }   void solve(int testCase) {     scanf( %d %d , &n, &m);     vii edges;     for (int i = 0; i < m; i++) {       int u, v;       scanf( %d %d , &u, &v);       adj[u].push_back({i + n + 1, v});       adj[v].push_back({i + n + 1, u});       edges.push_back({u, v});     }     level[1] = 0;     dfs(1, 0);     for (pair<int, int> E : edges) {       int u = cycleId[E.first];       int v = cycleId[E.second];       if (u != v) {         tree[u].push_back(v);         tree[v].push_back(u);       }     }     for (int i = 1; i <= n; i++) {       cact[cycleId[i]] = (cycleId[i] != i);     }     dfsTree(cycleId[1], 0);     int q;     scanf( %d , &q);     while (q--) {       int u, v;       scanf( %d %d , &u, &v);       printf( %lld n , calc(cycleId[u], cycleId[v]));     }   }   int main() {     int t = 1;     for (int testCase = 1; testCase <= t; testCase++) {       solve(testCase);     }     return 0;   }
#include <bits/stdc++.h>   const int maxn = 2e5 + 50;   using namespace std;   int n;   long long a[maxn], dp[maxn], he[maxn];   vector<int> maps[maxn];   void dfs(int u, int fa) {     he[u] = 0;     for (int i = 0, len = maps[u].size(); i < len; i++) {       int v = maps[u][i];       if (v != fa) {         dfs(v, u);         dp[u] += dp[v] + he[v];         he[u] += he[v];       }     }     he[u] += a[u];   }   long long ans;   void dfs1(int u, int fa) {     for (int i = 0, len = maps[u].size(); i < len; i++) {       int v = maps[u][i];       if (v != fa) {         dp[v] = dp[u] - he[v] + he[1] - he[v];         ans = max(ans, dp[v]);         dfs1(v, u);       }     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1, a, b; i < n; i++) {       scanf( %d%d , &a, &b);       maps[a].push_back(b);       maps[b].push_back(a);     }     dfs(1, 1);     ans = dp[1];     dfs1(1, 1);     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, k;     cin >> n >> k;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     long long maxa = 0;     for (int i = 0; i < k; i++) {       maxa += n - i;     }     vector<int> pos;     for (int i = 0; i < n; i++) {       if (a[i] > n - k) {         pos.emplace_back(i);       }     }     sort(pos.begin(), pos.end());     long long ans = 1;     for (int i = 1; i < pos.size(); i++) {       ans *= pos[i] - pos[i - 1];       ans %= mod;     }     cout << maxa <<     << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = 3.141592653589793238462643383;   int main() {     {       int n, m, k, t;       cin >> n >> m >> k >> t;       set<int> s;       ;       for (long long i = 0; i < k; i++) {         int a, b;         cin >> a >> b;         int id = (a - 1) * m + b;         s.insert(id);       };       for (long long i = 0; i < t; i++) {         int a, b;         cin >> a >> b;         int id = (a - 1) * m + b;         if (s.find(id) != s.end())           cout <<  Waste  << endl;         else {           auto it = lower_bound(s.begin(), s.end(), id);           int d = distance(s.begin(), it);           int val = (id - d) % 3;           if (val == 0)             cout <<  Grapes  << endl;           else if (val == 1)             cout <<  Carrots  << endl;           else             cout <<  Kiwis  << endl;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   array<string, 1510> arr;   unordered_set<string> f;   int n, k, t = int( S  +  E  +  T );   char get(char c1, char c2) {     if (c1 == c2) return c1;     return t - c1 - c2;   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) {       cin >> arr[i];       f.insert(arr[i]);     }     int res = 0;     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++) {         string s =   ;         for (int p = 0; p < k; p++) s.push_back(get(arr[i][p], arr[j][p]));         if (f.count(s)) res++;       }     printf( %d n , res / 3);   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());   int main() {     ios::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     int n;     cin >> n;     vector<int> a(n);     for (int& i : a) cin >> i;     int M = *min_element((a).begin(), (a).end());     int c = 0;     for (int& i : a) c += M == i;     if (c <= n / 2)       cout <<  Alice ;     else       cout <<  Bob ;     return 0;   }
#include <bits/stdc++.h>   int _min(int a, int b) {     if (a < b) return a;     return b;   }   int _max(int a, int b) {     if (a > b) return a;     return b;   }   int main() {     int i, j, k;     int n;     int x1, y1, x2, y2, x3, y3, res;     scanf( %d %d , &x1, &y1);     scanf( %d %d , &x2, &y2);     scanf( %d %d , &x3, &y3);     if ((x1 == x2 && x1 == x3) || (y1 == y2 && y1 == y3)) {       printf( 1 );       return 0;     }     if (x1 == x2) {       int min = _min(y1, y2);       int max = _max(y1, y2);       if (y3 <= min || y3 >= max) {         printf( 2 );         return 0;       }     }     if (y1 == y2) {       int min = _min(x1, x2);       int max = _max(x1, x2);       if (x3 <= min || x3 >= max) {         printf( 2 );         return 0;       }     }     if (x1 == x3) {       int min = _min(y1, y3);       int max = _max(y1, y3);       if (y2 <= min || y2 >= max) {         printf( 2 );         return 0;       }     }     if (y1 == y3) {       int min = _min(x1, x3);       int max = _max(x1, x3);       if (x2 <= min || x2 >= max) {         printf( 2 );         return 0;       }     }     if (x3 == x2) {       int min = _min(y3, y2);       int max = _max(y3, y2);       if (y1 <= min || y1 >= max) {         printf( 2 );         return 0;       }     }     if (y3 == y2) {       int min = _min(x3, x2);       int max = _max(x3, x2);       if (x1 <= min || x1 >= max) {         printf( 2 );         return 0;       }     }     printf( 3 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, m, ax, ay, cx, cy;   int d[100][100], s[100][100];   void take(int ax, int ay, int m) {     for (int y = ay; y < ay + m; ++y) {       for (int i = y; i <= k; ++i) ++s[ax][i];     }   }   int main() {     while (scanf( %d%d , &n, &k) != EOF) {       cx = cy = (k + 1) / 2;       memset(s, 0, sizeof(s));       for (int x = 1; x <= k; ++x)         for (int y = 1; y <= k; ++y)           d[x][y] = d[x][y - 1] + abs(x - cx) + abs(y - cy);       for (int i = 0; i < n; ++i) {         scanf( %d , &m);         int ax = -1, ay = -1, mini = 1000000000;         for (int x = 1; x <= k; ++x) {           for (int y = 1; y + m - 1 <= k; ++y) {             if (s[x][y + m - 1] - s[x][y - 1] == 0) {               if (d[x][y + m - 1] - d[x][y - 1] < mini) {                 ax = x, ay = y;                 mini = d[x][y + m - 1] - d[x][y - 1];               }             }           }         }         if (ax == -1) {           puts( -1 );         } else {           take(ax, ay, m);           printf( %d %d %d n , ax, ay, ay + m - 1);         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     int o = 0, s = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       s = s + a[i];       if ((a[i] % 2) != 0) {         o++;       }     }     if ((s % 2) == 0) {       cout << n - o;     } else {       cout << o;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2 * 1e5 + 100, mod = 1e9 + 7;   int n, k, a, b;   int dp[5010][5010], pr[5010][5010];   int add(int a, int b) {     a += b;     if (a < 0) a += mod;     if (a >= mod) a -= mod;     return a;   }   int main() {     scanf( %d%d%d%d , &n, &a, &b, &k);     dp[0][a] = 1;     for (int i = 0; i <= k; i++) {       if (i != 0) {         for (int j = 1; j <= n; j++) {           if (j > b) {             int t = ((j + b) >> 1) + 1;             dp[i][j] += add(add(pr[i - 1][n], -pr[i - 1][t - 1]), -dp[i - 1][j]);           } else if (j < b) {             int t = ((j + b - 1) >> 1);             dp[i][j] += add(pr[i - 1][t], -dp[i - 1][j]);           }         }       }       for (int j = 1; j <= n; j++) {         pr[i][j] = add(pr[i][j - 1], dp[i][j]);       }     }     cout << pr[k][n] % mod;   }
#include <bits/stdc++.h>   using namespace std;   const int n0 = 1503, inf = 1e9;   int n, s, m, k, a[n0], b[n0], p[n0], L[n0];   int dp[2][n0], mx[n0], best[n0];   int num(int pos) {     for (int i = 1; i <= n; i++) {       p[i] = p[i - 1] + (a[i] <= b[pos]);     }     memset(&dp, -0x3f, sizeof(dp));     int res = 0;     for (int i = 1; i <= m; i++) {       dp[(i - 1) & 1][0] = 0;       mx[0] = dp[(i - 1) & 1][0];       for (int j = 1; j <= n; j++) {         mx[j] = max(mx[j - 1], dp[(i - 1) & 1][j]);         if (L[j] != n0) {           if (best[j] != -1)             dp[i & 1][j] = dp[(i - 1) & 1][best[j]] - p[best[j]] + p[j];           dp[i & 1][j] = max(dp[i & 1][j], mx[L[j] - 1] + p[j] - p[L[j] - 1]);           if (i == m) res = max(res, dp[i & 1][j]);         }       }     }     return res;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     cin >> n >> s >> m >> k;     for (int i = 1; i <= n; i++) cin >> a[i], b[i] = a[i], L[i] = n0;     sort(b + 1, b + n + 1);     for (int i = 0; i < s; i++) {       int l, r;       cin >> l >> r;       L[r] = min(L[r], l);     }     for (int i = 1; i <= n; i++) {       best[i] = -1;       for (int j = L[i]; j < i; j++) {         if (best[i] == -1 || L[j] < L[best[i]]) best[i] = j;       }     }     int l = 0, r = n + 1;     while (l < r - 1) {       int mid = l + r >> 1;       if (num(mid) >= k)         r = mid;       else         l = mid;     }     if (r == n + 1)       cout << -1;     else       cout << b[r];   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 4e4 + 44;   const long long INF = 1e11 + 9;   const double eps = 1e-12;   int main() {     int t;     scanf( %d , &t);     long long x1, y1, x2, y2, n, m;     long long x3, y3, x4, y4;     long long answ = 0, ansb = 0;     while (t--) {       scanf( %lld , &n);       scanf( %lld , &m);       if (n % 2 == 0 || m % 2 == 0) {         answ = ansb = n * m / 2;       } else {         answ = (n * m) / 2 + 1;         ansb = answ - 1;       }       scanf( %lld , &x1);       scanf( %lld , &y1);       scanf( %lld , &x2);       scanf( %lld , &y2);       long long dx = x2 - x1 + 1, dy = y2 - y1 + 1;       if (dx % 2 == 0 || dy % 2 == 0) {         answ += (dx * dy) / 2;         ansb -= (dx * dy) / 2;       } else {         if (x1 % 2 && y1 % 2 || x1 % 2 == 0 && y1 % 2 == 0) {           answ += (dx * dy) / 2;           ansb -= (dx * dy) / 2;         } else {           answ += (dx * dy) / 2 + 1;           ansb -= (dx * dy) / 2 + 1;         }       }       scanf( %lld , &x3);       scanf( %lld , &y3);       scanf( %lld , &x4);       scanf( %lld , &y4);       dx = x4 - x3 + 1, dy = y4 - y3 + 1;       if (dx % 2 == 0 || dy % 2 == 0) {         answ -= (dx * dy) / 2;         ansb += (dx * dy) / 2;       } else {         if (x3 % 2 && y3 % 2 || x3 % 2 == 0 && y3 % 2 == 0) {           answ -= (dx * dy) / 2 + 1;           ansb += (dx * dy) / 2 + 1;         } else {           answ -= (dx * dy) / 2;           ansb += (dx * dy) / 2;         }       }       long long x5, y5, x6, y6;       if (y3 > y2 || y4 < y1 || x3 > x2 || x4 < x1) {         printf( %lld %lld n , answ, ansb);         continue;       }       x5 = max(x1, x3);       y5 = max(y1, y3);       x6 = min(x2, x4);       y6 = min(y2, y4);       dx = x6 - x5 + 1, dy = y6 - y5 + 1;       if (dx % 2 == 0 || dy % 2 == 0) {         if (x5 % 2 == 0 && y5 % 2 == 0 || x5 % 2 && y5 % 2) {           answ -= dx * dy / 2;           ansb += dx * dy / 2;         } else {           answ -= dx * dy / 2;           ansb += dx * dy / 2;         }       } else {         if (x5 % 2 && y5 % 2 || x5 % 2 == 0 && y5 % 2 == 0) {           answ -= dx * dy / 2;           ansb += dx * dy / 2;         } else {           answ -= dx * dy / 2 + 1;           ansb += dx * dy / 2 + 1;         }       }       printf( %lld %lld n , answ, ansb);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> deg(n), s(n);     for (int i = 0; i < n; i++) cin >> deg[i] >> s[i];     vector<pair<int, int>> edges;     queue<int> q;     for (int i = 0; i < n; i++)       if (deg[i] == 1) q.push(i);     while (!q.empty()) {       int leaf = q.front();       q.pop();       if (deg[leaf] != 1) continue;       int par = s[leaf];       edges.push_back({par, leaf});       deg[par] -= 1;       s[par] ^= leaf;       if (deg[par] == 1) q.push(par);     }     cout << edges.size() << endl;     for (auto p : edges) cout << p.first <<     << p.second <<   n ;   }