malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long a[100005], b;   int n, k;   pair<long long, int> pvec[100005];   int solve() {     for (int i = 0; i < n - 1; i++) pvec[i] = make_pair(a[i], i + 1);     sort(pvec, pvec + n);     reverse(pvec, pvec + n);     long long total = 0;     int ans = n;     for (int i = 0; i < k; i++) {       total += pvec[i].first;       ans = min(ans, pvec[i].second);     }     if (total > b) {       if (k > 1) b = b - (total - pvec[k - 1].first);       for (int j = 0; j < n; j++) {         if (a[j] > b) return j + 1;       }     } else       return n;     return 0;   }   int main() {     cin >> n >> k;     cin >> b;     for (int i = 0; i < n; i++) cin >> a[i];     cout << solve() << endl;     return 0;   }
#include <bits/stdc++.h>   const int B = 500;   using namespace std;   const long long inf = 1e9 + 12;   long long mod = 1e9 + 7;   const long long mxn = 4e5 + 5;   const int N = 10000005;   const double pi = 3.14159;   int dx[] = {0, 1, 0, -1, 1, -1, 1, -1};   int dy[] = {1, 0, -1, 0, -1, 1, 1, -1};   long long m, n, k, y, z;   vector<int> g[mxn];   int timer = 0;   int st[mxn], ed[mxn], d[mxn], tree[mxn << 4], lazy[mxn << 4];   bool lit[mxn];   void dfs(int v, int p) {     timer++;     st[v] = timer;     for (auto u : g[v]) {       if (u == p) continue;       dfs(u, v);     }     timer++;     ed[v] = timer;   }   void push_up(int node, int l, int r) {     int mid = (l + r) >> 1;     tree[node] = (lazy[2 * node] % 2 == 0 ? (tree[2 * node])                                           : (mid - l + 1 - tree[2 * node])) +                  (lazy[2 * node + 1] % 2 == 0 ? (tree[2 * node + 1])                                               : (r - mid - tree[2 * node + 1]));   }   void upd(int node, int l, int r, int ql, int qr, int t) {     if (ql > r || qr < l) return;     if (l >= ql && r <= qr) {       if (t)         lazy[node]++;       else         tree[node] = r - l + 1;       return;     }     int mid = (l + r) >> 1;     upd(2 * node, l, mid, ql, qr, t), upd(2 * node + 1, mid + 1, r, ql, qr, t);     push_up(node, l, r);   }   int qry(int node, int l, int r, int ql, int qr, int val) {     if (ql > r || qr < l) return 0;     if (l >= ql && r <= qr) {       val += lazy[node];       if (val % 2 == 0)         return tree[node];       else         return r - l + 1 - tree[node];     }     int mid = (l + r) >> 1;     return qry(2 * node, l, mid, ql, qr, val + lazy[node]) +            qry(2 * node + 1, mid + 1, r, ql, qr, val + lazy[node]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 2; i <= n; i++) {       int x;       cin >> x;       g[x].push_back(i), g[i].push_back(x);     }     dfs(1, 0);     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       lit[i] = x;       if (x) upd(1, 1, 2 * n, st[i], st[i], 0), upd(1, 1, 2 * n, ed[i], ed[i], 0);     }     cin >> k;     int t;     while (k--) {       string s;       cin >> s >> t;       if (s[0] ==  g ) {         cout << qry(1, 1, 2 * n, st[t], ed[t], 0) / 2 << endl;       } else {         upd(1, 1, 2 * n, st[t], ed[t], 1);       }     }   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   char block[][3][4] = {{ ..# ,  ### ,  ..# },                         { .#. ,  .#. ,  ### },                         { #.. ,  ### ,  #.. },                         { ### ,  .#. ,  .#. }};   int cell[10][10], anscell[10][10];   int bcnt, ans;   bool isPlacable(int i, int j, int k) {     for (int p = 0; p < 3; ++p)       for (int q = 0; q < 3; ++q) {         if (cell[i + p][j + q] != -1 && block[k][p][q] ==  # ) return false;       }     return true;   }   void setBlock(int i, int j, int k) {     for (int p = 0; p < 3; ++p)       for (int q = 0; q < 3; ++q) {         if (block[k][p][q] ==  # ) cell[i + p][j + q] = bcnt;       }     ++bcnt;   }   void removeBlock(int i, int j, int k) {     for (int p = 0; p < 3; ++p)       for (int q = 0; q < 3; ++q) {         if (block[k][p][q] ==  # ) cell[i + p][j + q] = -1;       }     --bcnt;   }   void go(int i, int j) {     if (j >= m - 2) {       go(i + 1, 0);       return;     }     if (i == n - 2) {       if (ans < bcnt) {         ans = bcnt;         memcpy(anscell, cell, sizeof(cell));       }       return;     }     if (bcnt + (int)((n * m - (i * m + j)) / 6.2) <= ans) {       return;     }     for (int k = 0; k < 4; ++k) {       if (isPlacable(i, j, k)) {         setBlock(i, j, k);         go(i, j + 1);         removeBlock(i, j, k);       }     }     go(i, j + 1);   }   int main() {     memset(cell, -1, sizeof(cell));     memset(anscell, -1, sizeof(anscell));     scanf( %d %d , &n, &m);     if (n >= 3 && m >= 3) go(0, 0);     printf( %d n , ans);     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         putchar(anscell[i][j] == -1 ?  .  : ( A  + anscell[i][j]));       }       putchar(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using uint = unsigned int;   using ll = long long;   using ull = unsigned long long;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   template <typename T1, typename T2>   ostream &operator<<(ostream &out, const pair<T1, T2> &item) {     out <<  (  << item.first <<  ,   << item.second <<  ) ;     return out;   }   template <typename T>   ostream &operator<<(ostream &out, const vector<T> &v) {     for (const auto &item : v) out << item <<    ;     return out;   }   const int NMAX = 200010;   struct lol {     int lv;     int v0;     int v1;     int v2;     int v3;     int v4;     lol(int v = 0) {       lv = v;       v0 = v;       v1 = v;       v2 = -v;       v3 = -v;       v4 = 0;     }     friend ostream &operator<<(ostream &out, const lol &a) {       return out <<  (  << a.lv <<     << a.v0 <<     << a.v1 <<     << a.v2                  <<     << a.v3 <<     << a.v4 <<  ) ;     }   };   int m;   string s;   lol st[NMAX << 2];   int val(char ch) { return (ch ==  (  ? 1 : -1); }   lol combine(const lol &a, const lol &b) {     lol ret;     ret.lv = a.lv + b.lv;     ret.v0 = min(a.v0, a.lv + b.v0);     ret.v1 = max(a.v1, a.lv + b.v1);     ret.v2 = max(max(a.v2, -a.lv + b.v2), a.v1 - 2 * (a.lv + b.v0));     ret.v3 = max(max(a.v3, -a.lv + b.v3), -2 * a.v0 + (a.lv + b.v1));     ret.v4 = max(max(a.v4, b.v4), max(a.v1 - a.lv + b.v3, a.v2 + a.lv + b.v1));     return ret;   }   void build(int node, int l, int r) {     if (l == r) return void(st[node] = lol(val(s[l])));     int mid = (l + r) / 2;     build(2 * node, l, mid);     build(2 * node + 1, mid + 1, r);     st[node] = combine(st[2 * node], st[2 * node + 1]);   }   void update(int node, int l, int r, int p) {     if (l == r) return void(st[node] = lol(val(s[p])));     int mid = (l + r) / 2;     if (p <= mid)       update(2 * node, l, mid, p);     else       update(2 * node + 1, mid + 1, r, p);     st[node] = combine(st[2 * node], st[2 * node + 1]);   }   int main() {     ios_base::sync_with_stdio(false);     int n, q;     cin >> n >> q;     m = 2 * n - 2;     cin >> s;     build(1, 0, m - 1);     cout << st[1].v4 <<   n ;     while (q--) {       int a, b;       cin >> a >> b;       --a;       --b;       swap(s[a], s[b]);       update(1, 0, m - 1, a);       update(1, 0, m - 1, b);       cout << st[1].v4 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       string a, b, c;       cin >> a >> b >> c;       int n = a.length();       int count = 0;       for (int i = 0; i < n; i++) {         if (c[i] == a[i] || c[i] == b[i])           continue;         else {           count++;           break;         }       }       if (count)         cout <<  NO  << endl;       else         cout <<  YES  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int k, n[3], t[3];     while (scanf( %d , &k) == 1) {       for (int i = 0; i < 3; i++) scanf( %d , &n[i]);       for (int i = 0; i < 3; i++) scanf( %d , &t[i]);       deque<int> q[3];       for (int i = 0; i < 3; i++) q[i].clear();       int p = 0;       while (k--) {         for (int i = 0; i < 3; i++)           if (q[i].size() == n[i]) {             p = q[i].front() + t[i];             for (int j = 0; j < 3; j++) {               while (q[j].size() && q[j].front() + t[j] <= p) q[j].pop_front();             }             i = -1;           }         for (int i = 0; i < 3; i++) q[i].push_back(p);       }       printf( %d n , p + t[0] + t[1] + t[2]);     }     return 0;   }
#include<bits/stdc++.h>       using namespace std;       typedef long long ll;   typedef pair<int, int> pii;   typedef long double ld;       #define F first   #define S second       const int MOD = 998244353;// XXX   const int C = 26;// XXX       void add(int &x, int y){    x += y;    while (x >= MOD) x -= MOD;    while (x < 0) x += MOD;   }       int fix(int x){    while (x >= MOD) x -= MOD;    while (x < 0) x += MOD;    return x;   }       int pw(int a, int b){    int ret = 1;    while (b){     if (b & 1)      ret = 1ll*ret*a%MOD;     b >>= 1;     a = 1ll*a*a%MOD;    }    return ret;   }      int mul(int a, int b) {    return (ll) a * b % MOD;   }      const int MAXN = 405;   const int MAXE = 605;      int n, m, d[MAXN][MAXN], ans[MAXN][MAXN];   pii edges[MAXE];      int onPath[MAXN], foundLen[MAXN], numPar[MAXN];      void solve() {    cin >> n >> m;    memset(d, 63, sizeof(d));       for(int i = 0; i < m; i++) {     int a, b; cin >> a >> b; --a; --b;     edges[i] = {a, b};     d[a][b] = d[b][a] = 1;    }    for(int i = 0; i < n; i++)     d[i][i] = 0;        for(int k = 0; k < n; k++)     for(int i = 0; i < n; i++)      for(int j = 0; j < n; j++)       d[i][j] = min(d[i][j], d[i][k] + d[k][j]);        for(int u = 0; u < n; u++) {     for(int v = 0; v < n; v++) {      bool ok = 1;      int cnt = 1;      memset(onPath, 0, sizeof(onPath));      memset(numPar, 0, sizeof(numPar));      memset(foundLen, 0, sizeof(foundLen));         for(int w = 0; w < n; w++) {       if(d[u][w] + d[v][w] == d[u][v]) {        onPath[w] = 1;        if(foundLen[d[u][w]])          ok = 0;        foundLen[d[u][w]] = 1;       }      }      for(int len = 0; len <= d[u][v]; len++)        if(!foundLen[len])         ok = 0;         for(int e = 0; e < m; e++) {       for(int rot = 0; rot < 2; rot++) {        auto &[a, b] = edges[e];        if(!onPath[a]) {         if(d[u][a] == d[u][b] + 1 && d[v][a] == d[v][b] + 1) {          ++numPar[a];         }        }        swap(a, b);       }      }      for(int w = 0; w < n; w++)        if(!onPath[w])        cnt = mul(cnt, numPar[w]);            if(ok)        ans[u][v] = cnt;     }    }        for(int u = 0; u < n; u++) {     for(int v = 0; v < n; v++) {      cout << ans[u][v] <<    ;     }     cout <<   n ;    }   }      int main(){    ios::sync_with_stdio(false);    cin.tie(0);    cout.tie(0);    // cout << fixed << setprecision(6);        int te = 1;     // cin >> te;    for (int w = 1; w <= te; w++){     // cout <<  Case #  << w <<  :  ;     solve();    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());   mt19937 rnf(2106);   const int N = 100005;   int n, m, k;   vector<int> a[N];   vector<int> v[2];   void dfs0(int x, int p, int z) {     v[z].push_back(x);     for (int i = 0; i < a[x].size(); ++i) {       int h = a[x][i];       if (h == p) continue;       dfs0(h, x, (z ^ 1));     }   }   bool c[N];   int dfs(int x, int p) {     c[x] = true;     for (int i = 0; i < a[x].size(); ++i) {       int h = a[x][i];       if (h == p) continue;       if (!c[h]) {         int u = dfs(h, x);         if (u) return u;       } else         return x;     }     return 0;   }   int p[N];   int d[N];   int f[N];   vector<int> bfs(int s) {     memset(c, false, sizeof c);     queue<int> q;     q.push(s);     c[s] = true;     int minu = N;     int xx, yy;     while (!q.empty()) {       int x = q.front();       q.pop();       for (int i = 0; i < a[x].size(); ++i) {         int h = a[x][i];         if (!c[h]) {           c[h] = true;           p[h] = x;           d[h] = d[x] + 1;           if (x != s)             f[h] = f[x];           else             f[h] = h;           q.push(h);         } else {           if (x != s && h != s) {             if (f[h] != f[x]) {               if (d[x] + d[h] < minu) {                 minu = d[x] + d[h];                 xx = x;                 yy = h;               }             }           }         }       }     }     vector<int> v;     for (int i = xx; i != s; i = p[i]) v.push_back(i);     vector<int> v1;     for (int i = yy; i != s; i = p[i]) v1.push_back(i);     reverse((v1).begin(), (v1).end());     v.push_back(s);     for (int i = 0; i < v1.size(); ++i) v.push_back(v1[i]);     return v;   }   void solv() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 0; i < m; ++i) {       int x, y;       scanf( %d%d , &x, &y);       a[x].push_back(y);       a[y].push_back(x);     }     if (m == n - 1) {       dfs0(1, 1, 0);       if (v[1].size() > v[0].size()) swap(v[0], v[1]);       printf( 1 n );       for (int i = 0; i < k / 2 + k % 2; ++i) printf( %d  , v[0][i]);       printf(  n );       return;     }     int s = dfs(1, -1);     vector<int> v = bfs(s);     if (v.size() <= k) {       printf( 2 n );       printf( %d n , v.size());       for (int i = 0; i < v.size(); ++i) printf( %d  , v[i]);       printf(  n );       return;     }     vector<int> vv;     for (int i = 0; i < v.size(); i += 2) vv.push_back(v[i]);     v = vv;     printf( 1 n );     for (int i = 0; i < k / 2 + k % 2; ++i) printf( %d  , v[i]);     printf(  n );   }   int main() {     solv();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAX = 2e5 + 9, LG = 35;   long long sum, b[MAX], c[MAX], a[MAX], n, k[LG];   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> b[i], sum += b[i];     for (int i = 0; i < n; i++) cin >> c[i], sum += c[i];     if (sum % (2 * n) != 0) return cout << -1, 0;     sum /= 2 * n;     for (int i = 0; i < n; i++) {       a[i] = b[i] + c[i] - sum;       if (a[i] % n != 0 || a[i] < 0) return cout << -1, 0;       a[i] /= n;       long long x = a[i];       for (int j = 0; j < LG; j++) k[j] += x >> j & 1;     }     for (int i = 0; i < n; i++) {       long long sum1 = 0, sum2 = 0;       for (int j = 0; j < LG; j++)         if (a[i] >> j & 1)           sum1 += k[j] * (1 << j), sum2 += n * (1 << j);         else           sum2 += k[j] * (1 << j);       if (sum1 != b[i] || sum2 != c[i]) return cout << -1, 0;     }     for (int i = 0; i < n; i++) cout << a[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   int mx1, my1, mx2, my2;   string in;   int main() {     ios::sync_with_stdio(0);     cin >> in;     mx1 = in[0] -  a  + 1;     my1 = in[1] -  0 ;     cin >> in;     mx2 = in[0] -  a  + 1;     my2 = in[1] -  0 ;     cout << max(abs(mx1 - mx2), abs(my1 - my2)) << endl;     while (1) {       if (mx1 == mx2 && my1 == my2) break;       if (mx1 > mx2) {         cout <<  L ;         mx1 -= 1;       } else if (mx1 < mx2) {         cout <<  R ;         mx1 += 1;       }       if (my1 < my2) {         cout <<  U ;         my1 += 1;       } else if (my1 > my2) {         cout <<  D ;         my1 -= 1;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void load() {}   const int N = 5e5 + 123;   const int inf = 1e9;   int a[N], v[N];   int dp[200][200];   void trungtt() {     int n, k, p;     scanf( %d%d%d , &n, &k, &p);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]), a[i] += a[i - 1], a[i] %= p;     if (k * p > n) {       for (int i = 0; i <= p; ++i)         for (int j = 0; j <= k; ++j) dp[i][j] = inf;       dp[0][0] = 0;       for (int i = 1; i <= n; ++i)         for (int j = k; j >= 1; --j)           for (int t = 0; t < p; ++t)             dp[a[i]][j] = min(dp[a[i]][j], dp[t][j - 1] + (a[i] - t + p) % p);       printf( %d , dp[a[n]][k]);     } else {       for (int i = 0; i <= n; ++i) v[i] = inf;       for (int i = 1; i < n; ++i) *upper_bound(v + 1, v + n, a[i]) = a[i];       if (v[k - 1] <= a[n])         printf( %d , a[n]);       else         printf( %d , a[n] + p);     }   }   int main() {     load();     trungtt();     return 0;   }
#include <bits/stdc++.h>   const int G[8][2] = {{0, 4}, {1, 5}, {2, 6}, {3, 7},                        {0, 2}, {1, 6}, {3, 4}, {5, 7}};   int f[(1 << 8)], g[1111];   int max(int a, int b) { return a > b ? a : b; }   int min(int a, int b) { return a < b ? a : b; }   int main() {     int n;     int i, j, k, _;     f[0] = 0;     memset(g, 0, sizeof g);     for (i = 0; i < 8; ++i) {       j = G[i][0];       k = G[i][1];       g[j] |= 1 << k;       g[k] |= 1 << j;     }     for (i = 1; i < (1 << 8); ++i) {       j = i & (i - 1);       f[i] = max(f[j], f[j & ~g[__builtin_ctz(i)]] + 1);     }     scanf( %d , &n);     n -= 2;     for (i = 1, j = n; i < j; ++i, --j) g[i] = (1 << 8) - 1;     if (i == j) g[i] = 0x55;     for (scanf( %d , &_); _; --_) {       scanf( %d%d , &i, &j);       --i;       --j;       k = min(i, n - i + 1);       g[k] &= (i == k ? ~0x44 : ~0x88);       k = min(j, n - j + 1);       g[k] &= (j == k ? ~0x11 : ~0x22);     }     for (k = 0, i = 1, j = n; i < j; ++i, --j) k += f[g[i]];     if (i == j && g[i]) ++k;     printf( %d , k);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = (int)1e9 + 7;   const int MAX = 1e6;   int len1, len2, pre[MAX], suf[MAX];   bool can_skip(int skip) {     for (int i = 1; i + skip - 1 < len1; i++)       if (pre[i - 1] + suf[i + skip] >= len2) return 1;     return 0;   }   int main() {     string x, y, z =  1 ;     cin >> x >> y;     z += x;     x = z;     len1 = x.length();     len2 = y.length();     for (int i = 1, j = 0, it = 0; i < len1; i++) {       if (j < len2 && x[i] == y[j]) it++, j++;       pre[i] = it;     }     for (int i = len1 - 1, j = len2 - 1, it = 0; i >= 1; i--) {       if (j >= 0 && x[i] == y[j]) it++, j--;       suf[i] = it;     }     int l = 0, r = len1, ans = 0;     while (l <= r) {       int mid = (l + r) >> 1;       if (can_skip(mid)) {         l = mid + 1, ans = mid;       } else         r = mid - 1;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     for (int i = 0; i < t; i++) {       int n;       cin >> n;       string x;       cin >> x;       string a(n,  0 );       string b(n,  0 );       for (int j = 0; j < n; j++) {         if (x[j] ==  0 ) {           a[j] =  0 ;           b[j] =  0 ;         } else if (x[j] ==  2 ) {           a[j] =  1 ;           b[j] =  1 ;         } else {           a[j] =  1 ;           b[j] =  0 ;           for (int k = j + 1; k < n; k++) {             a[k] =  0 ;             b[k] = x[k];           }           break;         }       }       cout << a << endl;       cout << b << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 100;   struct node {     int u, v, w, f, nxt;     node() {}     node(int u, int v, int w, int f, int nxt)         : u(u), v(v), w(w), f(f), nxt(nxt) {}   } e[N << 2];   int h[N], idx = 1;   void link(int x, int y, int w) {     e[++idx] = node(x, y, w, 1, h[x]);     h[x] = idx;     e[++idx] = node(y, x, -w, 0, h[y]);     h[y] = idx;   }   int dis[N], pre[N];   bool vis[N];   int n, m;   int Mincost = 0;   int spfa() {     memset(dis, 0x3f, sizeof dis);     memset(vis, 0, sizeof vis);     memset(pre, 0, sizeof pre);     queue<int> q;     while (q.size()) q.pop();     q.push(1);     dis[1] = 0;     while (q.size()) {       int t = q.front();       q.pop();       vis[t] = 0;       for (int i = h[t]; i; i = e[i].nxt) {         int v = e[i].v, w = e[i].w;         if (e[i].f && dis[v] > dis[t] + w) {           dis[v] = dis[t] + w;           pre[v] = i;           if (vis[v] == 0) {             vis[v] = 1;             q.push(v);           }         }       }     }     if (dis[n] == 0x3f3f3f3f) return 0;     Mincost += dis[n];     for (int i = pre[n]; i; i = pre[e[i].u]) e[i].f--, e[i ^ 1].f++;     return 1;   }   int main() {     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int x, y, z;       cin >> x >> y >> z;       link(x, y, z);     }     vector<int> v;     v.clear();     while (spfa()) {       v.push_back(Mincost);     }     int m;     cin >> m;     while (m--) {       int x;       cin >> x;       double ans = 1e18;       for (int i = 0; i < v.size(); i++)         ans = min(ans, 1.0 * (v[i] + x) / (i + 1));       printf( %.10f n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cerr.tie(nullptr);     int n, i, j, tmp, tmp2;     cin >> n >> tmp;     for (i = 1; i < n; i++) {       cin >> tmp2;       if (tmp == tmp2) {         for (i = i + 1; i < n; i++) {           cin >> tmp2;           if (tmp > tmp2) {             tmp = tmp2;             for (i = i + 1; i < n; i++) {               cin >> tmp2;               if (tmp <= tmp2) {                 cout <<  NO  << endl;                 return 0;               }               tmp = tmp2;             }           } else if (tmp < tmp2) {             cout <<  NO  << endl;             return 0;           }         }       } else if (tmp > tmp2) {         tmp = tmp2;         for (i = i + 1; i < n; i++) {           cin >> tmp2;           if (tmp <= tmp2) {             cout <<  NO  << endl;             return 0;           }           tmp = tmp2;         }       }       tmp = tmp2;     }     cout <<  YES  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e4 + 5;   const int LOG = 16;   struct trie {     int go[N][2], NFI = 1;     trie() { memset(go, -1, sizeof(go)); }     void reset() {       for (int i = 0; i <= NFI; i++) go[i][0] = go[i][1] = -1;       NFI = 1;     }     void add(int x) {       for (int at = 1, bit = LOG - 1; bit >= 0; bit--) {         int t = x >> bit & 1;         if (go[at][t] == -1) go[at][t] = ++NFI;         at = go[at][t];       }     }     int ask(int x) {       int res = 0;       for (int at = 1, bit = LOG - 1; bit >= 0; bit--) {         int t = x >> bit & 1;         if (go[at][!t] != -1) {           res |= (1 << bit);           at = go[at][!t];         } else           at = go[at][t];       }       return res;     }   } t;   int n, q, a[N];   vector<int> nb[N];   int par[N], dep[N], jump_256[N];   void DFS_prep(int v) {     for (int u : nb[v]) {       if (u != par[v]) {         par[u] = v;         dep[u] = dep[v] + 1;         DFS_prep(u);       }     }   }   int res[N][256];   void precalc(int v) {     t.reset();     int temp = v;     for (int i = 0; temp && i <= 255; i++) {       t.add(a[temp] ^ i);       temp = par[temp];     }     jump_256[v] = temp;     for (int i = 0; i < 256; i++) res[v][i] = t.ask(i * 256);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> q;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       nb[u].push_back(v);       nb[v].push_back(u);     }     DFS_prep(1);     for (int i = 1; i <= n; i++) precalc(i);     while (q--) {       int u, v;       cin >> u >> v;       int ans = 0;       int jumps = 0;       while (v && dep[jump_256[v]] > dep[u]) {         ans = max(ans, res[v][jumps]);         jumps++;         v = jump_256[v];       }       jumps *= 256;       while (v && dep[v] >= dep[u]) {         ans = max(ans, a[v] ^ jumps);         v = par[v];         jumps++;       }       cout << ans <<   n ;     }     return 0;   }