malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n;     cin >> t;     string s;     for (int i = 0; i < t; i++) {       cin >> n;       cin >> s;       int k = 0;       if (n % 2 == 0) {         for (int i = 1; i < n; i += 2)           if ((int(s[i]) - 48) % 2 == 0) {             k = 1;             cout << 2 <<   n ;             break;           }         if (k == 0) cout << 1 <<   n ;       }       if (n % 2 == 1) {         for (int i = 0; i < n; i += 2)           if ((int(s[i]) - 48) % 2 == 1) {             k = 1;             cout << 1 <<   n ;             break;           }         if (k == 0) cout << 2 <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, x, y, num[100005], res, a[100005], b[100005];   bool vis[100005];   vector<int> v[100005];   void dfs(long long now, long long pre) {     for (long long i = 0; i < v[now].size(); i++) {       int j = v[now][i];       if (j != pre) {         dfs(j, now);         a[now] = max(a[now], a[j]);         b[now] = max(b[now], b[j]);       }     }     num[now] += a[now];     num[now] -= b[now];     if (num[now] < 0)       a[now] += -num[now];     else       b[now] += num[now];   }   int main() {     cin >> n;     for (long long i = 0; i < n - 1; i++) {       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     for (long long i = 1; i <= n; i++) cin >> num[i];     dfs(1, -1);     res = a[1] + b[1];     cout << res <<   n ;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC target( sse4,avx )   const int p = 1000000007;   int mul32(int x, int y) { return int(int64_t(x) * y % p); }   int add32(int x, int y) {     int res = x + y;     if (res >= p) res -= p;     return res;   }   int sub32(int x, int y) {     int res = x - y;     if (res < 0) res += p;     return res;   }   void run(std::istream &in, std::ostream &out) {     int n;     in >> n;     std::vector<int> xs(n);     for (int i = 0; i < n; i++) {       in >> xs[i];     }     std::sort(xs.begin(), xs.end());     std::vector<int> pow2(n + 1);     pow2[0] = 1;     for (int i = 1; i <= n; i++) {       pow2[i] = (pow2[i - 1] * 2) % p;     }     int res = 0;     for (int i = 0; i < n; i++) {       res = add32(res, mul32(xs[i], pow2[i]));       res = sub32(res, mul32(xs[i], pow2[n - i - 1]));     }     out << res << std::endl;   }   int main() {     std::cin.sync_with_stdio(false);     std::cin.tie(nullptr);     run(std::cin, std::cout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 10;   long long n, d, b, a[N], f[N];   int main() {     long long i, j, k, t = 0, ans;     scanf( %I64d%I64d%I64d , &n, &d, &b);     for (i = 1; i <= n; i++) scanf( %I64d , &a[i]), f[i] = f[i - 1] + a[i];     for (i = 1; i <= n / 2; i++)       if (f[min(i * d + i, n)] >= (t + 1) * b) t++;     ans = t;     t = 0;     for (i = 1; i <= n / 2; i++) swap(a[i], a[n - i + 1]);     f[0] = 0;     for (i = 1; i <= n; i++) f[i] = f[i - 1] + a[i];     for (i = 1; i <= n / 2; i++)       if (f[min(i * d + i, n)] >= (t + 1) * b) t++;     printf( %I64d , n / 2 - min(ans, t));   }
#include <bits/stdc++.h>   using namespace std;   int Get() {     char c;     while (c = getchar(), c <  0  || c >  9 )       ;     int X = 0;     while (c >=  0  && c <=  9 ) {       X = X * 10 + c - 48;       c = getchar();     }     return X;   }   const int inf = 1000000000;   int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }   int Solve(int a, int b, int c) {     return a ? ((c - b * Solve(b % a, a, c % a)) / a) : 0;   }   int GetMin(int L, int R, int a, int b, int c) {     if (L > R) return -1;     int K = GCD(a, b);     if (c % K) return -1;     a /= K;     b /= K;     c /= K;     int X = Solve(a, b, c);     if (X < L) X += ((L - X - 1) / b + 1) * b;     if (X > L) X -= (X - L) / b * b;     return (X <= R) ? X : -1;   }   int GetMax(int L, int R, int a, int b, int c) {     if (L > R) return -1;     int K = GCD(a, b);     if (c % K) return -1;     a /= K;     b /= K;     c /= K;     int X = Solve(a, b, c);     if (X > R) X -= ((X - R - 1) / b + 1) * b;     if (X < R) X += (R - X) / b * b;     return (X >= L) ? X : -1;   }   int main() {     int N = Get(), S = Get(), a = 0, b = 0, c = 0;     while (N--) {       int X = Get();       if (X == 3) a++;       if (X == 4) b++;       if (X == 5) c++;     }     int Ans = inf, Ans_x, Ans_y;     for (int y = 0; b * y <= S; y++) {       int B = b * y, _S = S - B, Max = min(y, (_S - c * y) / a), x;       x = GetMin((_S - B - 1) / a + 1, min(Max, B / a), a, c, _S);       if (x != -1 && 2 * B - _S < Ans) {         Ans = 2 * B - _S;         Ans_x = x;         Ans_y = y;       }       x = GetMax(0, min(Max, min(B, _S - B) / a), a, c, _S);       if (x != -1 && _S - 2 * a * x < Ans) {         Ans = _S - 2 * a * x;         Ans_x = x;         Ans_y = y;       }       x = GetMin((max(B, _S - B) - 1) / a + 1, Max, a, c, _S);       if (x != -1 && 2 * a * x - _S < Ans) {         Ans = 2 * a * x - _S;         Ans_x = x;         Ans_y = y;       }       x = GetMin((B - 1) / a + 1, min(Max, (_S - B) / a), a, c, _S);       if (x != -1 && _S - 2 * B < Ans) {         Ans = _S - 2 * B;         Ans_x = x;         Ans_y = y;       }     }     if (Ans == inf)       printf( -1 n );     else       printf( %d %d %d n , Ans_x, Ans_y, (S - a * Ans_x - b * Ans_y) / c);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long grundy[1234];   int main() {     long long idx = 1, i, j;     for (i = 1; i <= 15; i++) {       for (j = 1; j <= (i + 1); j++) {         grundy[idx] = i;         idx++;       }     }     long long n;     cin >> n;     long long ans = 0;     while (n--) {       long long va;       cin >> va;       ans = ans ^ grundy[va];     }     cout << ((ans == 0) ?  YES  :  NO );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d, e;     scanf( %d%d%d%d%d , &a, &b, &c, &d, &e);     if ((a + b + c + d + e) % 5 == 0 && a + b + c + d + e >= 5)       printf( %d n , (a + b + c + d + e) / 5);     else       printf( -1 n );   }
#include <bits/stdc++.h>   using namespace std;   long long n, a[100005], b[100005], fa[100005], s[100005], q[100005], l,       p = -2147483647;   inline long long find(long long x) {     if (x == fa[x]) return x;     return fa[x] = find(fa[x]);   }   inline long long M(long long u, long long v) { return u > v ? u : v; }   int main() {     scanf( %lld , &n);     for (long long i = 1; i <= n; i++) scanf( %lld , &a[i]);     for (long long i = 1; i <= n; i++) scanf( %lld , &b[i]);     for (long long i = n; i >= 1; i--) {       long long k = b[i];       if (!fa[k]) fa[k] = k, s[k] = a[k];       long long fk = find(k);       if (fa[k - 1] && k - 1 > 0) {         long long fl = find(k - 1);         if (fk != fl) s[k] += s[fl], s[fl] = 0, fa[fl] = k;       }       if (fa[k + 1] && k + 1 <= n) {         long long fr = find(k + 1);         if (fk != fr) s[k] += s[fr], s[fr] = 0, fa[fr] = k;       }       p = M(p, s[k]), q[++l] = p;     }     for (long long i = n - 1; i >= 0; i--) printf( %lld n , q[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int h, w, i, j, mod = 1e9 + 7, r, c, ans = 1, a[1001][1001];   int main() {     cin.tie(NULL);     ios_base::sync_with_stdio(0);     cin >> h >> w;     for (i = 0; i < h; i++) {       cin >> r;       for (j = 0; j < r; j++) a[i][j] = 2;       a[i][r] = 1;     }     for (i = 0; i < w; i++) {       cin >> c;       for (j = 0; j < c; j++)         if (a[j][i] == 1) {           cout << 0 << endl;           return 0;         } else           a[j][i] = 2;       if (a[c][i] == 2) {         cout << 0 << endl;         return 0;       }       a[c][i] = 1;     }     for (i = 0; i < h; i++)       for (j = 0; j < w; j++)         if (!a[i][j]) ans = (ans * 2) % mod;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> v[200010], circle;   int fa[200010], dep[200010], a[200010], b[200010], n, rt, vs, vt, h1, h2;   bool vis[200010], bo[200010];   inline int rd() {     int x = 0;     char ch = getchar();     for (; ch <  0  || ch >  9 ; ch = getchar())       ;     for (; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch -  0 ;     return x;   }   inline void dfs(int x) {     for (int i = 0, siz = v[x].size(); i < siz; i++) {       int t = v[x][i];       if (t == fa[x]) continue;       dep[t] = dep[x] + 1;       fa[t] = x;       dfs(t);     }   }   inline bool gao() {     int p = 0, q = 0;     bool flag = true;     for (int i = 1; i <= n; i++)       if (a[i] != b[i] && dep[i] > dep[p]) p = i;     if (!p) return true;     for (int hh = p; a[hh] != b[hh]; hh = fa[hh])       bo[hh] = true, circle.push_back(hh);     for (int i = 1; i <= n; i++)       if (a[i] != b[i] && !bo[i] && dep[i] > dep[q]) q = i;     if (q) {       reverse(circle.begin(), circle.end());       flag = false;       for (int hh = q; a[hh] != b[hh]; hh = fa[hh])         bo[hh] = true, circle.push_back(hh);     } else       q = fa[circle.back()];     for (int i = 1; i <= n; i++)       if (a[i] != b[i] && !bo[i]) return false;     int h1 = p, h2 = q;     for (; h1 != h2; h1 = fa[h1])       if (dep[h1] < dep[h2]) swap(h1, h2);     rt = h1;     if (circle.size() != dep[p] + dep[q] - dep[rt] * 2) return false;     vs = p;     vt = q;     if (flag) reverse(circle.begin(), circle.end());     return true;   }   int main() {     n = rd();     for (int i = 1; i <= n; i++)       if (!(a[i] = rd())) h1 = i;     for (int i = 1; i <= n; i++)       if (!(b[i] = rd())) h2 = i;     for (int i = 1; i < n; i++) {       int x = rd(), y = rd();       v[x].push_back(y);       v[y].push_back(x);     }     dep[0] = -1;     dfs(h2);     for (int hh = h1; hh != h2; hh = fa[hh]) swap(a[hh], a[fa[hh]]);     long long ans = dep[h1];     if (!gao()) {       puts( -1 );       return 0;     }     if (!circle.size()) {       printf( 0 %d n , ans);       return 0;     }     for (int i = h1; i; i = fa[i]) vis[i] = true;     if (vis[circle.back()] && !vis[circle[0]])       reverse(circle.begin(), circle.end());     int gap = 0, siz = circle.size();     for (int i = 0; i < siz; i++)       if (b[circle[i]] == a[circle[0]]) gap = i;     for (int i = 0; i < siz; i++)       if (b[circle[(i + gap) % siz]] != a[circle[i]]) {         puts( -1 );         return 0;       }     if (vis[circle[0]] || vis[circle.back()]) {       int now = siz;       for (int i = 0; i < siz; i++)         if (!vis[circle[i]]) {           now = i;           break;         }       ans = ans - now +             min((long long)gap * (siz + 1) + now,                 abs((long long)(siz - gap) * (siz + 1) - now));     } else       ans = (ans + (long long)min(gap, siz - gap) * (siz + 1));     for (; !vis[rt]; rt = fa[rt]) ans += 2;     if (vs > vt) swap(vs, vt);     printf( %d %d %I64d n , vs, vt, ans);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   using i64 = long long;   using i32 = int;   using f64 = long double;   template <class Key>   using vec = vector<Key>;   template <class Key>   using heap = priority_queue<Key>;   template <class Key>   using hash_set = unordered_set<Key>;   template <class Key, class Value>   using hash_map = unordered_map<Key, Value>;   using str = string;   template <size_t Size1>   using a64 = array<i64, Size1>;   template <size_t Size1, size_t Size2>   using aa64 = array<a64<Size2>, Size1>;   template <size_t Size1, size_t Size2, size_t Size3>   using aaa64 = array<aa64<Size2, Size3>, Size1>;   using p64 = pair<i64, i64>;   using v64 = vec<i64>;   using vv64 = vec<v64>;   using s64 = set<i64>;   using m64 = map<i64, i64>;   mt19937 gen(998244353);   const i64 inf = numeric_limits<i64>::max() / 2;   template <typename T>   inline i64 sz(const T& a) {     return (i64)(a.size());   }   inline void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }   template <typename T>   inline bool check_min(T& a, T b) {     if (a > b) return a = b, 1;     return 0;   }   template <typename T>   inline bool check_max(T& a, T b) {     if (a < b) return a = b, 1;     return 0;   }   struct Problem {     Problem(bool multitest = 0) {       read();       if (!multitest) solve();     }     void solve(), read();   };   signed main() {     fast();     Problem();     return 0;   }   i64 n, m;   v64 a, b;   vv64 c;   i64 dist(i64 from, i64 to) { return (to - from + n) % n; }   void Problem::solve() {     c.resize(n);     for (i64 i = 0; i < m; i++) {       c[a[i]].push_back(dist(a[i], b[i]));     }     for (i64 i = 0; i < sz(c); i++) {       sort((c[i]).begin(), (c[i]).end());     }     for (i64 i = 0; i < n; i++) {       i64 ans = 0;       for (i64 j = 0; j < n; j++) {         if (c[j].empty()) continue;         i64 cur = dist(i, j) + (sz(c[j]) - 1) * n + c[j][0];         check_max(ans, cur);       }       cout << ans <<    ;     }   }   void Problem::read() {     cin >> n >> m;     a.resize(m), b.resize(m);     for (i64 i = 0; i < m; i++) {       cin >> a[i] >> b[i];       --a[i], --b[i];     }   }
#include <bits/stdc++.h>   using std::max;   int n, m, c, x[150000 + 1], a, b, i;   long long p[150000 + 1], ans = 0;   struct node {     long long sum, mmax, lmax, rmax;     void update(const node &l, const node &r) {       sum = l.sum + r.sum;       lmax = max(l.lmax, l.sum + r.lmax);       rmax = max(l.rmax + r.sum, r.rmax);       mmax = max(l.mmax, max(r.mmax, l.rmax + r.lmax));     }   } tree[(150000 << 2) + 1];   void build(int x, int l, int r) {     if (l == r) {       tree[x].sum = tree[x].mmax = tree[x].lmax = tree[x].rmax = p[l];       return;     }     int mid = (l + r) >> 1;     build(x << 1, l, mid);     build((x << 1) + 1, mid + 1, r);     tree[x].update(tree[x << 1], tree[(x << 1) + 1]);   }   node find(int x, int l, int r, int s, int t) {     if (s == l && t == r) return tree[x];     int mid = (l + r) >> 1;     if (t <= mid) return find(x << 1, l, mid, s, t);     if (s > mid) return find((x << 1) + 1, mid + 1, r, s, t);     node ret;     ret.update(find(x << 1, l, mid, s, mid),                find((x << 1) + 1, mid + 1, r, mid + 1, t));     return ret;   }   int main() {     scanf( %d%d%d , &n, &m, &c);     for (i = 1; i <= n; ++i) scanf( %d , x + i);     for (i = 1; i < n; ++i) scanf( %d , p + i);     for (i = 1; i < n; ++i) p[i] = 50 * (x[i + 1] - x[i]) - p[i] * c;     --n;     build(1, 1, n);     for (i = 1; i <= m; ++i) {       scanf( %d%d , &a, &b);       ans += max(0LL, find(1, 1, n, a, b - 1).mmax);     }     printf( %0.9llf n , (double)ans / 100);     return 0;   }
#include <bits/stdc++.h>   int pn, pr[2000050];   bool np[2000050] = {0};   int n;   int ln, ls[2000050];   inline void gen() {     pn = 0;     for (int i = 2; i < 2000050; i++) {       if (np[i]) continue;       pr[pn++] = i;       if (i > 2000) continue;       for (int j = i * i; j < 2000050; j += i) np[j] = 1;     }   }   inline int solve() {     int i, j, p, c = 0;     if (n == 2) return 0;     std::sort(ls, ls + ln);     if (ln && ls[0] == 1) return 1;     j = 0;     for (i = 0; i < pn && pr[i] < n; i++) {       p = pr[i];       while (j < ln && ls[j] < p) j++;       if (j >= ln || ls[j] != p) return -1;       c++;     }     return c;   }   int main(void) {     gen();     while (scanf( %d %d , &ln, &n) == 2) {       for (int i = 0; i < ln; i++) scanf( %d , ls + i);       printf( %d n , solve());     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long power(long long a, long long b) {     if (b == 0) return 1;     if (b == 1) return a;     if (b % 2 == 1) return (power(a, b - 1) * a);     long long q = power(a, b / 2);     return (q * q);   }   void solve() {     long long n;     cin >> n;     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < n; j++) {         if (i == j or i == j + 1 or i == j - 1)           cout << 1 <<    ;         else           cout << 0 <<    ;       }       cout << endl;     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cout.tie(NULL);     cin.tie(NULL);     long long t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int rev(int a) {     int ans = 0;     int shift = 0;     while (shift <= 7) {       ans |= (a & 1 << shift ? 1 : 0) << (7 - shift);       shift++;     }     return ans;   }   int main() {     string a;     int prev = 0;     getline(cin, a);     for (int i = 0; i < a.length(); i++) {       int val = rev(a[i]);       int res = prev - val;       if (res > 0)         cout << ((res) % 256) << endl;       else         cout << (256 + res) % 256 << endl;       prev = val;     }     return 0;   }
#include<cstdio>   #include<iostream>   #include<algorithm>   int main()   {    int n;    char a[100000];    bool x = 1;    while (~scanf( %d , &n)) {     while (n--) {      x = 1;      scanf( %s , a);      for (int i = 0; a[i] !=   0 ; i++) {       if (x) {        if (a[i] !=  a )         a[i] =  a ;        else         a[i] =  b ;        x = 0;       }       else {        if (a[i] !=  z )         a[i] =  z ;        else         a[i] =  z  - 1;        x = 1;       }      }      printf( %s n , a);     }    }     return 0;          }
#include <bits/stdc++.h>   using namespace std;   typedef struct trie {     char c;     bool win, lose;     struct trie *alphabet[26];   } trie;   void addString(trie *T, char *s);   trie *initTrie(char c);   void dfs(trie *T);   int main() {     int i, n, k;     char s[100005];     trie *T = initTrie(  0 );     scanf( %d%d , &n, &k);     for (i = 0; i < n; i++) {       scanf( %s , s);       addString(T, s);     }     dfs(T);     if (!(T->win))       printf( Second n );     else if (T->win && T->lose)       printf( First n );     else if (T->win && !(T->lose)) {       if (k % 2)         printf( First n );       else         printf( Second n );     }     return 0;   }   void dfs(trie *T) {     int i, flag = 1;     for (i = 0; i < 26; i++) {       if (T->alphabet[i]) {         flag = 0;         dfs(T->alphabet[i]);         T->win |= !(T->alphabet[i]->win);         T->lose |= !(T->alphabet[i]->lose);       }     }     if (flag) {       T->win = false;       T->lose = true;     }   }   trie *initTrie(char c) {     int i;     trie *T = (trie *)malloc(sizeof(trie));     T->win = T->lose = false;     T->c = c;     for (i = 0; i < 26; i++) T->alphabet[i] = NULL;     return T;   }   void addString(trie *T, char *s) {     int len = strlen(s), i;     for (i = 0; i < len; i++) {       if (T->alphabet[s[i] -  a ] == NULL)         T->alphabet[s[i] -  a ] = initTrie(s[i]);       T = T->alphabet[s[i] -  a ];     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string str;     cin >> str;     if (str[0] >  4  && str[0] !=  9 ) str[0] = (char)( 9  - str[0] +  0 );     for (int x = 1; x < (int)str.length(); x++)       if (str[x] >  4 ) str[x] = (char)( 9  - str[x] +  0 );     cout << str << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   int dp[N][3][2];   string a;   int n;   int solve(int x, int state, int start) {     if (x >= n) return 0;     if (dp[x][state][start] != -1) return dp[x][state][start];     int res = 0;     if (state == 0) {       if (start == a[x])         res = max(solve(x + 1, 0, 1 - start) + 1, solve(x + 1, 1, start));       else         res = max(solve(x + 1, 1, 1 - start) + 1, solve(x + 1, 0, start));     }     if (state == 1) {       if (start == a[x])         res = max(solve(x + 1, 2, 1 - start) + 1, solve(x + 1, 1, start));       else         res = max(solve(x + 1, 2, start), solve(x + 1, 1, 1 - start) + 1);     }     if (state == 2) {       if (start == a[x])         res = solve(x + 1, 2, 1 - start) + 1;       else         res = solve(x + 1, 2, start);     }     dp[x][state][start] = res;     return res;   }   int main() {     std::ios::sync_with_stdio(false);     ;     cin >> n;     memset((dp), (-1), sizeof(dp));     cin >> a;     for (int i = 0; i < n; i++) a[i] -=  0 ;     cout << solve(0, 0, a[0]) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int *a = new int[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < n; i++) {       if (i > 0 && i < n - 1) {         if (abs(a[i] - a[i + 1]) < abs(a[i] - a[i - 1]))           cout << abs(a[i] - a[i + 1]);         else           cout << abs(a[i] - a[i - 1]);         if (abs(a[i] - a[n - 1]) < abs(a[i] - a[0]))           cout <<     << abs(a[i] - a[0]) << endl;         else           cout <<     << abs(a[i] - a[n - 1]) << endl;       } else {         if (i == 0) {           cout << abs(a[i] - a[i + 1]);           cout <<     << abs(a[i] - a[n - 1]) << endl;         } else if (i == n - 1) {           cout << abs(a[i] - a[i - 1]);           cout <<     << abs(a[0] - a[n - 1]) << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e4 + 5;   int main() {     int k, n, s, p;     cin >> k >> n >> s >> p;     int ans = k * (n % s == 0 ? n / s : n / s + 1);     if (ans % p == 0)       cout << ans / p << endl;     else       cout << ans / p + 1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   const int inf = ~0u >> 2;   int numa[N], numb[N], pos[N];   struct node {     int val, id;     node(int _val, int _id) { val = _val, id = _id; }     bool operator<(const node& A) const { return val > A.val; }   };   int now[N], unuse[N];   priority_queue<node> A, B;   int __ans[N];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       scanf( %d , &numa[i]);       pos[numa[i]] = i;     }     for (int i = 0; i < n; i++) {       scanf( %d , &numb[i]);       int val = i - pos[numb[i]];       if (val < 0)         B.push(node(abs(val), i));       else         A.push(node(abs(val), i));       now[i] = val;     }     int tmp = 0, len = 0;     for (int k = n - 1; k >= 0; k--) {       int pa = A.empty() ? inf : A.top().val + tmp;       int pb = B.empty() ? inf : B.top().val - tmp;       __ans[len++] = min(pa, pb);       while (pb == 0) {         int id = B.top().id;         A.push(node(-tmp, id));         B.pop();         if (B.empty()) break;         pb = B.top().val - tmp;       }       unuse[k] = 1;       int np = pos[numb[k]];       now[k] = -np - tmp - 1;       while (!A.empty() && (A.top().val + tmp != abs(now[A.top().id] + tmp) &&                             unuse[A.top().id])) {         unuse[A.top().id] = 0;         A.pop();       }       tmp++;       if (np == 0)         A.push(node(-tmp, k));       else         B.push(node(np + tmp, k));     }     cout << __ans[0] << endl;     for (int i = len - 1; i; i--) printf( %d n , __ans[i]);   }
#pragma GCC optimize( Ofast )   #include<bits/stdc++.h>   using namespace std;      #define int long long int   #define double long double      #define all(x) begin(x), end(x)   #define Done(x) cout<<x<<endl; return;   #define endl   n       void solve(){    int q; cin>>q;    for(int i=0;i<q;i++){     int u; cin>>u;     int v; cin>>v;     if(v<u){      cout<< NO <<endl;     }else if(v==u){      cout<< YES <<endl;     }else{      vector<int>cnt(31);      for(int i=0;i<30;i++){       if(u&(1<<i)){        cnt[i]++;       }      }      bool can=true;      for(int i=0;i<30;i++){       int val=(1<<i);       if(v&val){        if(cnt[i]==0){         can=false;         break;        }else{         cnt[i]-=1;         cnt[i+1]+=cnt[i];        }       }else{        cnt[i+1]+=cnt[i];       }      }      if(can){       cout<< YES <<endl;      }else{       cout<< NO <<endl;      }     }    }   }      int32_t main(){    // Remove for Interactive Problems    ios_base::sync_with_stdio(false);    cin.tie(0); cout.tie(0);       solve();        cerr<< Time :  <<1000*((double)clock())/(double)CLOCKS_PER_SEC<< ms n ;    return 0;   }