malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   using LL = long long;   constexpr int N = 1e5 + 5;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n, m, x, y;     cin >> n >> m >> x >> y;     x--;     y--;     string s;     cin >> s;     vector<vector<int>> mat(n, vector<int>(m, -1));     for (int i = 0; i < s.size(); i++) {       if (mat[x][y] == -1) mat[x][y] = i;       if (s[i] ==  U ) x = max(x - 1, 0);       if (s[i] ==  D ) x = min(x + 1, n - 1);       if (s[i] ==  R ) y = min(y + 1, m - 1);       if (s[i] ==  L ) y = max(y - 1, 0);     }     vector<int> ans(s.size() + 1);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (mat[i][j] == -1) {           ans[s.size()]++;         } else {           ans[mat[i][j]]++;         }       }     }     for (int x : ans) cout << x <<    ;   }
#include <bits/stdc++.h>   using namespace std;   const int mx = 2e5 + 10;   const int mxb = 60;   long long int a[mx], b[mx], c[mx];   int cnt[mxb][2];   int bat(int idx, long long int v) {     if (v & (1ll << idx)) return 1;     return 0;   }   int main() {     int n;     scanf( %d , &n);     long long int sm = 0;     for (int i = 0; i < n; i++) scanf( %lld , b + i);     for (int i = 0; i < n; i++) scanf( %lld , c + i), sm += b[i] + c[i];     sm /= n + n;     for (int i = 0; i < n; i++) {       a[i] = (b[i] + c[i] - sm) / n;       if (a[i] < 0) {         puts( -1 );         return 0;       }       for (int j = 0; j < mxb; j++) cnt[j][bat(j, a[i])]++;     }     for (int i = 0; i < n; i++) {       long long int bi = 0, ci = 0;       int cb = 0, cc = 0;       for (int j = 0; j < mxb; j++) {         int db = cb, dc = cc;         for (int x = 0; x < 2; x++) {           db += cnt[j][x] * (bat(j, a[i]) & x);           dc += cnt[j][x] * (bat(j, a[i]) | x);         }         cb = db / 2, cc = dc / 2;         if (db & 1) bi |= (1ll << j);         if (dc & 1) ci |= (1ll << j);       }       if (bi != b[i] || ci != c[i]) {         puts( -1 );         return 0;       }     }     for (int i = 0; i < n; i++) printf( %lld  , a[i]);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d, e, f;     cin >> a >> b >> c >> d >> e >> f;     int sum = 0;     bool flag = false;     if (f > e) {       int x = min(b, min(c, d));       sum += f * x;       b -= x;       c -= x;       d -= x;       flag = true;     } else {       int y = min(a, d);       sum += e * y;       a -= y;       d -= y;     }     if (flag == true) {       int y = min(a, d);       sum += e * y;     } else {       int x = min(b, min(c, d));       sum += f * x;     }     cout << sum;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void pisz(int n) { printf( %d n , n); }   const int fx[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};   const int fxx[9][2] = {{0, 0}, {0, 1},  {0, -1}, {1, 0},  {-1, 0},                          {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};   const int N = 500;   const long long mod = 1000000007;   struct FenwickTreeMax {     vector<int> bit;     int n;     FenwickTreeMax(int n) {       this->n = n;       bit.assign(n, 0);     }     FenwickTreeMax(vector<int> a) : FenwickTreeMax(a.size()) {       for (size_t i = 0; i < a.size(); i++) update(i, a[i]);     }     int getmax(int r) {       int ret = 0;       for (; r >= 0; r = (r & (r + 1)) - 1) ret = (ret < bit[r] ? bit[r] : ret);       return ret;     }     int pos_val(int r) { return bit[r]; }     void update(int idx, int val) {       for (; idx < n; idx = idx | (idx + 1))         bit[idx] = (bit[idx] < val ? val : bit[idx]);     }   };   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     string s;     cin >> s;     vector<long long> pos[26];     for (long long i = 0; i < n; i++) {       pos[s[i] -  a ].push_back(i);     }     FenwickTreeMax ft(n);     vector<long long> output(n, -1);     long long maxi = 0;     for (long long i = 25; i >= 0; i--) {       if (pos[i].size() == 0) continue;       vector<long long> col;       for (auto x : pos[i]) {         output[x] = ft.getmax(x) + 1;         maxi = (output[x] < maxi ? maxi : output[x]);       }       for (auto x : pos[i]) {         ft.update(x, output[x]);       }     }     cout << maxi <<   n ;     for (long long i = 0; i < n; i++) {       cout << output[i] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int>> vec;   int main() {     int n;     cin >> n;     for (int tt = 0; tt < n; tt++) {       int x, y;       cin >> x >> y;       vec.push_back({x, y});     }     sort(vec.begin(), vec.end());     int ans = -1;     for (int i = 0; i < n; i++) {       if (ans <= vec[i].second)         ans = vec[i].second;       else         ans = vec[i].first;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int T;   string s, ans;   bool exist[30];   int main() {     scanf( %d , &T);     for (int i = 0; i < T; i++) {       cin >> s;       ans.clear();       for (int j = 0; j < 26; j++) {         exist[j] = false;       }       ans = s[0];       exist[s[0] -  a ] = true;       bool Done = true;       for (int j = 1; j < s.length(); j++) {         if (!exist[s[j] -  a ]) {           if (ans.front() == s[j - 1]) {             ans = s[j] + ans;           } else if (ans.back() == s[j - 1]) {             ans.push_back(s[j]);           } else {             Done = false;             break;           }           exist[s[j] -  a ] = true;         } else {           int count = 0;           for (int k = 0; k < ans.length(); k++) {             if (ans[k] == s[j - 1]) {               count = k;               break;             }           }           if (count == 0) {             if (ans[1] != s[j]) {               Done = false;               break;             } else {               continue;             }           }           if (count == ans.length() - 1) {             if (ans[count - 1] != s[j]) {               Done = false;               break;             } else {               continue;             }           }           if (ans[count - 1] != s[j] && ans[count + 1] != s[j]) {             Done = false;             break;           }         }       }       if (!Done) {         cout <<  NO  << endl;       } else {         cout <<  YES  << endl;         cout << ans;         for (int j = 0; j < 26; j++) {           if (!exist[j]) {             cout << char( a  + j);           }         }       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   int n, first, second, a, b, m, d[(1 << 17) + 5], p[(1 << 17) + 5];   vector<int> g[(1 << 17) + 5];   bool check(int nod, int par, int del, int hg) {     int kids = g[nod].size();     if (par) kids--;     if (nod == del) {       if (hg == 1)         return 0;       else if (hg == 2) {         if (kids != 1) return 0;         for (int i : g[nod]) {           if (i != par) return check(i, nod, del, hg - 1);         }       } else {         if (kids != 3) return 0;         for (int i : g[nod]) {           if (i != par) kids -= check(i, nod, del, hg - 1);         }         if (kids != 2) return 0;         for (int i : g[nod]) {           if (i != par) kids -= check(i, nod, del, hg - 2);         }         if (kids != 0) return 0;         return 1;       }     } else {       if (hg == 1)         return (kids == 0);       else {         if (kids != 2) return 0;         for (int i : g[nod]) {           if (i != par) kids -= check(i, nod, del, hg - 1);         }         return (kids == 0);       }     }   }   bool good(int del, int root) { return check(root, 0, del, n); }   int32_t main() {     ios_base ::sync_with_stdio(0);     cin.tie();     cout.tie();     cin >> n;     m = (1 << n) - 2;     for (int i = 1; i < m; i++) {       cin >> first >> second;       g[first].push_back(second);       g[second].push_back(first);     }     for (int i = 1; i <= m; i++) {       if (g[i].size() == 2) {         int gd = 1;         for (int j : g[i]) {           if (g[j].size() == 1) gd = 0;         }         if (gd)           b = i;         else           a = i;       } else if (g[i].size() == 4)         a = i;     }     if (a && b && good(a, b)) {       cout << 1 <<   n  << a;       return 0;     }     int st = 0;     for (int i = 1; i <= m; i++) {       if (g[i].size() == 1) st = i;     }     queue<int> q;     d[st] = 1;     p[st] = 0;     q.push(st);     while (q.size()) {       int nod = q.front();       q.pop();       for (int i : g[nod]) {         if (!d[i]) d[i] = d[nod] + 1, p[i] = nod, q.push(i);       }     }     st = 0;     for (int i = 1; i <= m; i++) {       if (d[i] == 2 * n - 2) st = i;     }     for (int i = 1; i <= n - 2; i++) st = p[st];     a = st;     b = p[st];     if (a && b && good(a, a)) {       cout << 2 <<   n  << min(a, b) <<     << max(a, b);       return 0;     }     cout << 0;   }
#include <bits/stdc++.h>   const int MAXN = 2000 + 5;   long long mn = 1e18;   int ans[3][2], k = -1;   int n, m;   long long a[MAXN], b[MAXN];   inline long long mabs(long long x) { return x < 0 ? -x : x; }   int main() {     scanf( %d , &n);     long long s1 = 0, s2 = 0;     for (int i = 1; i <= n; ++i) scanf( %lld , a + i), s1 += a[i];     scanf( %d , &m);     for (int i = 1; i <= m; ++i) scanf( %lld , b + i), s2 += b[i];     mn = mabs(s1 - s2);     k = 0;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         if (mn > mabs(s1 - s2 - 2 * a[i] + 2 * b[j])) {           mn = mabs(s1 - s2 - 2 * a[i] + 2 * b[j]);           k = 1;           ans[1][0] = i;           ans[1][1] = j;         }       }     }     std::vector<long long> S1, S2;     long long t1 = -1, t2 = -1;     for (int i = 1; i <= n; ++i)       for (int j = i + 1; j <= n; ++j) S1.push_back(2ll * (a[i] + a[j]));     for (int i = 1; i <= m; ++i)       for (int j = i + 1; j <= m; ++j) S2.push_back(2ll * (b[i] + b[j]));     std::sort(S1.begin(), S1.end());     std::sort(S2.begin(), S2.end());     for (auto x : S1) {       long long now = s1 - s2 - x;       auto p = std::upper_bound(S2.begin(), S2.end(), -now);       if (p != S2.end()) {         if (mn > mabs(now + *p)) {           mn = mabs(now + *p);           t1 = x;           t2 = *p;           k = 2;         }       }       if (p != S2.begin()) {         --p;         if (mn > mabs(now + *p)) {           mn = mabs(now + *p);           t1 = x;           t2 = *p;           k = 2;         }       }     }     if (k == 2) {       for (int i = 1; i <= n; ++i)         for (int j = i + 1; j <= n; ++j)           if (2ll * (a[i] + a[j]) == t1) {             ans[1][0] = i;             ans[2][0] = j;             break;           }       for (int i = 1; i <= m; ++i)         for (int j = i + 1; j <= m; ++j)           if (2ll * (b[i] + b[j]) == t2) {             ans[1][1] = i;             ans[2][1] = j;             break;           }     }     printf( %lld n%d n , mn, k);     for (int i = 1; i <= k; ++i) {       printf( %d %d n , ans[i][0], ans[i][1]);     }     auto chk = [&]() {       for (int i = 1; i <= k; ++i) std::swap(a[ans[i][0]], b[ans[i][1]]);       long long sm0 = 0, sm1 = 0;       for (int i = 1; i <= n; ++i) sm0 += a[i];       for (int i = 1; i <= m; ++i) sm1 += b[i];       assert(mabs(sm0 - sm1) == mn);     };     chk();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     string l =  312931303130313130313031 ;     string input =   ;     string s =  312831303130313130313031 ;     string s1 = s + s + s;     string s2 = l + s + s;     string s3 = s + l + s;     string s4 = s + s + l;     long long int i;     for (i = 0; i < n; i++) {       string ch;       cin >> ch;       input += ch;     }     long long int flag1 = 0, flag2 = 0, flag3 = 0, flag4 = 0;     for (i = 0; i < s1.length() - 2 * n; i++) {       if (input.compare(s1.substr(i, n * 2)) == 0) {         flag1 = 1;       }     }     for (i = 0; i < s2.length() - 2 * n; i++) {       if (input.compare(s2.substr(i, 2 * n)) == 0) {         flag2 = 1;       }     }     for (i = 0; i < s3.length() - 2 * n; i++) {       if (input.compare(s3.substr(i, 2 * n)) == 0) {         flag3 = 1;       }     }     for (i = 0; i < s4.length() - 2 * n; i++) {       if (input.compare(s4.substr(i, 2 * n)) == 0) {         flag4 = 1;       }     }     if (flag1 || flag2 || flag3 || flag4) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5005;   const long long inf = 1e15;   long long dp[2][N][2];   int a[N][2];   void load() {}   void trungtt() {     int n, x;     scanf( %d%d , &n, &x);     long long ans = 0;     int l = x, r = x;     for (int i = 1; i <= n; ++i) {       int a, b;       scanf( %d%d , &a, &b);       if (l > b) {         ans += l - b;         r = l;         l = b;       } else if (r < a) {         ans += a - r;         l = r, r = a;       } else {         if (l < a) l = a;         if (r > b) r = b;       }     }     printf( %lld , ans);     return;   }   int main() {     load();     trungtt();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool upmin(T &x, T y) {     return y < x ? x = y, 1 : 0;   }   template <typename T>   inline bool upmax(T &x, T y) {     return x < y ? x = y, 1 : 0;   }   const long double eps = 1e-11;   const long double pi = acos(-1);   const int oo = 1 << 30;   const long long loo = 1ll << 62;   const int mods = 1e9 + 7;   const int MAXN = 5005;   const int INF = 0x3f3f3f3f;   inline int read() {     int f = 1, x = 0;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = (x << 3) + (x << 1) + (c ^ 48);       c = getchar();     }     return x * f;   }   struct anode {     int u, v;     long long c;   };   vector<anode> Ans;   long long a[MAXN];   int f[MAXN][MAXN], frm[MAXN][MAXN], flag[MAXN], n, k, V;   void add(int u, int v, long long c) {     long long t = min(c * k, a[u]);     a[u] -= t, a[v] += t;     Ans.push_back((anode){u, v, c});   }   signed main() {     long long sum = 0;     n = read(), k = read(), V = read();     for (int i = 1; i <= n; i++) a[i] = read(), sum += a[i];     if (sum < V) {       puts( NO );       return 0;     }     f[0][0] = 1;     for (int i = 1; i <= n; i++)       for (int j = 0; j < k; j++)         if (f[i - 1][j])           f[i][j] = 1, frm[i][j] = 0;         else if (f[i - 1][(j - a[i] % k + k) % k])           f[i][j] = 1, frm[i][j] = 1;     int nw = V % k, id1 = 0, id2 = 0;     if (!f[n][nw]) {       puts( NO );       return 0;     }     puts( YES );     for (int i = n; i >= 1; i--) {       if (frm[i][nw])         flag[i] = 1, nw = (nw - a[i] % k + k) % k, id1 = i;       else         id2 = i;     }     for (int i = 1; i <= n; i++)       if (a[i] && i != id1 && i != id2) {         if (flag[i])           add(i, id1, (a[i] - 1) / k + 1);         else           add(i, id2, (a[i] - 1) / k + 1);       }     if (!id1) id1 = (id2 == n ? id2 - 1 : id2 + 1);     if (!id2) id2 = (id1 == n ? id1 - 1 : id1 + 1);     if (a[id1] > V) add(id1, id2, (a[id1] - V) / k);     if (a[id1] < V) add(id2, id1, (V - a[id1]) / k);     for (auto v : Ans) printf( %lld %d %d n , v.c, v.u, v.v);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d %d  , &n, &m);     char A[147][10047];     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) scanf( %c  , &A[i][j]);     int P[147][10047];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) P[i][j] = -1;       queue<int> Q;       for (int j = 0; j < m; j++)         if (A[i][j] ==  1 ) {           Q.push(j);           Q.push(0);           P[i][j] = 0;         }       while (!Q.empty()) {         int kde = Q.front();         Q.pop();         int kolko = Q.front();         Q.pop();         int dx[] = {1, -1};         for (int k = 0; k < 2; k++) {           int kde1 = kde + dx[k];           kde1 += m;           kde1 %= m;           if (P[i][kde1] == -1) {             P[i][kde1] = kolko + 1;             Q.push(kde1);             Q.push(kolko + 1);           }         }       }     }     int vys = -1;     int V[10047];     for (int i = 0; i < m; i++) V[i] = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         if (P[i][j] == -1)           V[j] = -1;         else if (V[j] != -1)           V[j] += P[i][j];       }     vys = V[0];     for (int i = 0; i < m; i++) vys = min(vys, V[i]);     printf( %d n , vys);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> mat[100010];   int vis[100010], val[100010];   int dfs(int p, int pa) {     if (vis[p]) return 1;     int ret = 0;     vis[p] = 1;     if (p != pa) val[p] += val[pa];     for (auto x : mat[p]) ret = max(ret, dfs(x, p));     return ret;   }   int in[100010], out[100010], n, dp[302][100002][2];   int rec(int p, int r, int t) {     if (p == n + 1) return (r == 0);     if (r < 0) return 0;     int &temp = dp[p][r][t];     if (temp != -1) return temp;     temp = 0;     if (!out[p] || t) temp += rec(p + 1, r, 0);     if (temp > 1000000007) temp -= 1000000007;     temp += rec(p, r - val[p], 1);     if (temp > 1000000007) temp -= 1000000007;     return temp;   }   int main() {     ios::sync_with_stdio(0);     int q, t, u, v;     cin >> n >> q >> t;     for (int i = 1; i <= n; i++) cin >> val[i];     for (int i = 0; i <= q - 1; i++) {       cin >> u >> v;       mat[u].push_back(v);       in[v]++;       out[u]++;     }     int chao = 0;     for (int i = 1; i <= n; i++)       if (!vis[i] && !in[i]) chao = max(chao, dfs(i, i));     for (int i = 1; i <= n; i++)       if (!vis[i]) chao = 1;     memset(dp, -1, sizeof(dp));     if (chao)       cout << 0 << endl;     else       cout << rec(1, t, 0) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int B[300000];   pair<int, int> A[300000];   stack<pair<int, int> > s;   queue<pair<pair<int, int>, int> > q;   int main() {     int N, l, f, i;     long long ta = 0, tb = 0;     scanf( %d , &N);     for (i = 0; i < N; ++i)       scanf( %d , &A[i].first), A[i].second = i, ta += A[i].first;     for (i = 0; i < N; ++i) scanf( %d , &B[i]), tb += B[i];     sort(A, A + N);     sort(B, B + N);     if (ta != tb) {       printf( NO n );       return 0;     }     for (i = 0; i < N; ++i) {       if (A[i].first < B[i])         s.emplace(B[i] - A[i].first, A[i].second);       else {         l = A[i].first - B[i];         while (l && !s.empty()) {           q.emplace(make_pair(s.top().second + 1, A[i].second + 1),                     f = min(l, s.top().first));           s.top().first -= f;           l -= f;           if (!s.top().first) s.pop();         }         if (l) {           printf( NO n );           return 0;         }       }     }     printf( YES n );     printf( %d n , q.size());     while (!q.empty())       printf( %d %d %d n , q.front().first.first, q.front().first.second,              q.front().second),           q.pop();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   set<int> s[40];   set<int>::iterator it, q;   int n, m, k, sol, v[40];   int main() {     int i, j;     scanf( %d %d , &n, &m);     for (i = 1; i <= n; i++) {       scanf( %d , &v[i]);       v[i] %= m;     }     if (n == 1) {       printf( %d , v[1]);       return 0;     }     if (n == 2) {       printf( %d , max((v[1] + v[2]) % m, max(v[1], v[2])));       return 0;     }     k = n / 2;     for (i = 1; i <= n; i++) {       s[i].insert(v[i]);       if (i != k + 1) {         for (it = s[i - 1].begin(); it != s[i - 1].end(); it++) {           j = *it;           s[i].insert(j);           j += v[i];           j %= m;           s[i].insert(j);         }         s[i - 1].clear();       }     }     it = s[k].end();     it--;     sol = *it;     it = s[n].end();     it--;     sol = max(sol, int(*it));     if (s[n].begin() != s[n].end())       for (it = s[k].begin(); it != s[k].end(); it++) {         i = *it;         j = m - i;         q = s[n].lower_bound(j);         if (q != s[n].begin()) {           q--;           sol = max(sol, (i + int(*q)) % m);         }         q = s[n].end();         q--;         sol = max(sol, int((1LL * i + int(*q)) % m));       }     printf( %d , sol);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char M[10][10];   int V[10];   int main() {     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> M[i];     for (int i = 0; i < k; i++) V[i] = i;     long ans(1e10);     do {       long mx(0), mn(1e10);       for (int i = 0; i < n; i++) {         long num = 0;         for (int j = 0; j < k; j++) {           num = num * 10 + (M[i][V[j]] -  0 );         }         mx = max(mx, num);         mn = min(mn, num);       }       ans = min(ans, mx - mn);     } while (next_permutation(V, V + k));     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     cin >> t;     while (t--) {       int n, mx = -1;       cin >> n;       int arr[n];       for (int i = 0; i < n; i++) {         cin >> arr[i];         mx = max(mx, arr[i]);       }       int ans = -1;       for (int i = 1; i < n; i++)         if (arr[i] == mx && arr[i - 1] != mx) ans = i + 1;       for (int i = 0; i < n - 1; i++)         if (arr[i] == mx && arr[i + 1] != mx) ans = i + 1;       cout << ans << (  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int min(int a, int b) {     if (a < b) return a;     return b;   }   int Abs(int a) {     if (a < 0)       return -a;     else       return a;   }   double Abs(double a) {     if (a < 0)       return -a;     else       return a;   }   unsigned long long sqr(unsigned long long a) { return a * a; }   double sqr(double a) { return a * a; }   int main() {     int a, b, c;     cin >> a >> b;     c = 0;     while (b) {       c = c * 10 + b % 10;       b /= 10;     }     cout << a + c << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m;   vector<long long> boxes;   vector<int> counts;   long long answer;   void In() {     boxes.clear();     counts.clear();     answer = 0;     cin >> n >> m;     boxes.resize(m);     counts.resize(63);     for (int i = 0; i < m; i++) cin >> boxes[i];   }   long long Solve() {     long long sum = 0;     for (long long box : boxes) sum += box;     if (sum < n) return -1;     for (long long box : boxes) counts[log2(box)]++;     for (int i = 0; i <= log2(n); i++)       if ((1 << i) & n) {         for (int j = 0; j < i; j++) {           counts[j + 1] += counts[j] / 2;           counts[j] %= 2;         }         if (!counts[i])           for (int j = i + 1; j < 63; j++)             if (counts[j]) {               while (j != i) {                 counts[j]--;                 j--;                 counts[j] += 2;                 answer++;               }               break;             }         counts[i]--;       }     return answer;   }   void Out() { cout << answer << endl; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     cin >> t;     while (t--) {       In();       answer = Solve();       Out();     }   }
#include <bits/stdc++.h>   int x, y, u, v, d = 1, a, b;   int main() {     for (scanf( %d%d , &a, &b); a; b /= 4, d *= 2, --a) {       if (b % 4 == 0)         u = y, v = x;       else if (b % 4 == 1)         u = x, v = y + d;       else if (b % 4 == 2)         u = x + d, v = y + d;       else         u = 2 * d - y - 1, v = d - x - 1;       x = u, y = v;     }     printf( %d %d n , x, y);     return 0;   }