malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     scanf( %d , &n);     int block = (int)sqrt(n), total = 0;     for (int t = 1;; ++t) {       for (int j = 1, k = max(1, n - t * block + 1); j <= block; ++j, ++k) {         printf( %d  , k);         if (++total == n) {           return 0;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k, i;     cin >> n >> m >> k;     vector<long long int> a(n), s1(m, 0), e1(m, 0), tot1(m, 0), s2(n, 0),         e2(n, 0), tot2(n, 0);     long long int b[m][3];     long long int c[k][2];     for (i = 0; i < n; i++) cin >> a[i];     for (i = 0; i < m; i++) {       cin >> b[i][0] >> b[i][1] >> b[i][2];       b[i][0]--;       b[i][1]--;     }     for (i = 0; i < k; i++) {       cin >> c[i][0] >> c[i][1];       c[i][0]--;       c[i][1]--;       s1[c[i][0]]++;       e1[c[i][1]]++;     }     long long int sum = 0;     for (i = 0; i < m; i++) {       tot1[i] = sum + s1[i];       sum += s1[i] - e1[i];     }     for (i = 0; i < m; i++) {       s2[b[i][0]] += tot1[i] * b[i][2];       e2[b[i][1]] += tot1[i] * b[i][2];     }     sum = 0;     for (i = 0; i < n; i++) {       tot2[i] = sum + s2[i] + a[i];       sum += s2[i] - e2[i];       cout << tot2[i] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n % 2 == 0)       cout <<  -1  << endl;     else {       for (int i = 0; i < n; i++) {         if (i > 0) cout <<    ;         cout << i;       }       cout << endl;       for (int i = 0; i < n; i++) {         if (i > 0) cout <<    ;         cout << i;       }       cout << endl;       for (int i = 0; i < n; i++) {         if (i > 0) cout <<    ;         cout << (i + i) % n;       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   long long a, b, c, d, e, f, n, ans, cn1, cn2, cn3, t;   string s, s1, s2;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> a;     cin >> b;     cin >> c;     cin >> d;     cin >> e;     cin >> f;     ans = 0;     if (e >= f) {       ans = min(a, d);       d = d - ans;       ans = ans * e;       ans += min(b, min(c, d)) * f;       cout << ans;     } else if (e < f) {       ans = 0;       ans = min(b, min(c, d));       d = d - ans;       ans = ans * f;       ans += min(a, d) * e;       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, a, b;     cin >> n >> m;     if (m == n) {       vector<bool> rev(n, false);       vector<vector<int> > mat(n + 1);       for (int i = 0; i < m; i++) {         cin >> a >> b;         mat[a].push_back(b);         mat[b].push_back(a);       }       int cont = 0;       for (int i = 1; i <= m; i++) {         if (!rev[i]) {           cont++;           queue<int> COLA;           COLA.push(i);           rev[i] = true;           while (!COLA.empty()) {             int j = COLA.front();             COLA.pop();             for (int k = 0; k < mat[j].size(); k++) {               if (!rev[mat[j][k]]) {                 rev[mat[j][k]] = 1;                 COLA.push(mat[j][k]);               }             }           }         }       }       if (cont == 1)         cout <<  FHTAGN! n ;       else         cout <<  NO n ;     } else       cout <<  NO n ;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector )   #pragma GCC target( avx )   int V[100000];   float x;   int main() {     int n, m, l, r, res, type;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &V[i]);     while (m--) {       scanf( %d%d%d%f , &type, &l, &r, &x);       if (type == 1)         for (int i = l; i <= r; ++i) V[i] -= V[i] > x ? x : 0;       else {         res = 0;         for (int i = l; i <= r; ++i) V[i] == x ? ++res : 0;         printf( %d n , res);       }     }   }
#include <bits/stdc++.h>   using namespace std;   #define TC 1   #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);   #define deb(...)   [  << #__VA_ARGS__  :   << (__VA_ARGS__) <<  ]     using ll = long long;      template <typename T>   vector<T> readArr(int n) {       vector <T> v(n);       for (auto &it : v)           cin >> it;       return v;   }      void init() {       ;   }      const int N = 1e5+ 5;      void solve() {       int n, m; cin >> n >> m;              vector <int> v = readArr<int>(n);              for (int &x: v)           x = x % m;              vector <int> ct(N);       for (int x: v)           ct[x]++;                  int res = (ct[0] > 0 ? 1 : 0);     //  cout << deb(res) <<   n ;       for (int i=1; i<=m/2; i++) {           int j = m - i;           if (i == j) {               res += (ct[j] > 0 ? 1 : 0);              // cout << deb(i) deb(res) <<   n ;               continue;           }           int a = ct[i], b = ct[j];           if (a > 0 && b > 0) {               res++;               if (a <= b) {                   ct[i] = 0;                   ct[j] -= (a+1);                   ct[j] = max(ct[j], 0);               } else {                   ct[j] = 0;                   ct[i] -= (b+1);                   ct[i] = max(ct[i], 0);               }           }                                 res += ct[i];           res += ct[j];                     // cout << deb(i) deb(j) deb(res) <<   n ;       }       cout << res <<   n ;   }      int main() {       IOS       init();       int t = 1;       if (TC)           cin >> t;          while (t--) {           solve();       }   }
#include <bits/stdc++.h>   template <class T>   T gcd(T a, T b) {     T r;     while (b != 0) {       r = a % b;       a = b;       b = r;     }     return a;   }   template <class T>   T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   using namespace std;   const long long MOD = 1e9 + 7;   vector<int> p, q;   long long res[200005];   void act() {     long long a, b, c, d, cnt = 0;     cin >> a >> b >> c >> d;     for (int i = 1; i <= c; i++) p.push_back(2);     for (int i = 1; i <= a; i++) p.push_back(0);     for (int i = 1; i <= d; i++) q.push_back(3);     for (int i = 1; i <= b; i++) q.push_back(1);     if (p.size() <= q.size()) swap(p, q);     for (int i = 0; i < p.size(); i++) {       res[++cnt] = p[i];       if (i < q.size()) res[++cnt] = q[i];     }     for (int i = 1; i < cnt; i++)       if (abs(res[i] - res[i + 1]) != 1) {         cout <<  NO               <<   n ;         return;       }     cout <<  YES           <<   n ;     for (int i = 1; i <= cnt; i++) cout << res[i] <<    ;   }   int main() {     int t = 1;     while (t--) act();   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int n;   int a[N], b[N], c[N];   map<pair<int, int>, pair<int, int> > mtp;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d %d %d , &a[i], &b[i], &c[i]);     }     double ans = 0;     int idx = -1;     for (int i = 1; i <= n; i++) {       double curr = min(min(a[i], b[i]), c[i]);       curr /= 2.0;       if (curr > ans) {         ans = curr;         idx = i;       }     }     int idx1 = -1, idx2 = -1;     for (int i = 1; i <= n; ++i) {       int aa = a[i];       int bb = b[i];       int cc = c[i];       if (mtp.find({min(aa, bb), max(aa, bb)}) != mtp.end()) {         int key = mtp[{min(aa, bb), max(aa, bb)}].first;         int backtrack = mtp[{min(aa, bb), max(aa, bb)}].second;         double curr = min(min(aa, bb), key + cc);         curr /= 2.0;         if (curr > ans) {           ans = curr;           idx1 = i;           idx2 = backtrack;         }       }       if (mtp.find({min(bb, cc), max(bb, cc)}) != mtp.end()) {         int key = mtp[{min(bb, cc), max(bb, cc)}].first;         int backtrack = mtp[{min(bb, cc), max(bb, cc)}].second;         double curr = min(min(bb, cc), key + aa);         curr /= 2.0;         if (curr > ans) {           ans = curr;           idx1 = i;           idx2 = backtrack;         }       }       if (mtp.find({min(aa, cc), max(aa, cc)}) != mtp.end()) {         int key = mtp[{min(aa, cc), max(aa, cc)}].first;         int backtrack = mtp[{min(aa, cc), max(aa, cc)}].second;         double curr = min(min(aa, cc), key + bb);         curr /= 2.0;         if (curr > ans) {           ans = curr;           idx1 = i;           idx2 = backtrack;         }       }       int x = min(aa, bb);       int y = max(aa, bb);       if (mtp.find({x, y}) == mtp.end()) {         mtp[{x, y}] = {cc, i};       } else {         if (cc > mtp[{x, y}].first) {           mtp[{x, y}] = {cc, i};         }       }       x = min(cc, bb);       y = max(cc, bb);       if (mtp.find({x, y}) == mtp.end()) {         mtp[{x, y}] = {aa, i};       } else {         if (aa > mtp[{x, y}].first) {           mtp[{x, y}] = {aa, i};         }       }       x = min(aa, cc);       y = max(aa, cc);       if (mtp.find({x, y}) == mtp.end()) {         mtp[{x, y}] = {bb, i};       } else {         if (bb > mtp[{x, y}].first) {           mtp[{x, y}] = {bb, i};         }       }     }     if (idx2 == -1) {       printf( 1 n%d n , idx);     } else {       printf( 2 n%d %d n , idx1, idx2);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, a, b, x1, y1, x2, y2, d1, d2, r1 = 10000000000000000,                                                r2 = 10000000000000000, ans;     ans = r2;     r1 *= -1;     r2 = r1;     vector<pair<long long, pair<long long, long long> > > v1, v2;     cin >> n >> x1 >> y1 >> x2 >> y2;     for (int i = 0; i < n; i++) {       cin >> a >> b;       d1 = (y1 - b) * (y1 - b) + (x1 - a) * (x1 - a);       d2 = (y2 - b) * (y2 - b) + (x2 - a) * (x2 - a);       v1.push_back(make_pair(d1, make_pair(a, b)));       v2.push_back(make_pair(d2, make_pair(a, b)));     }     v1.push_back(make_pair(0, make_pair(x1, y1)));     sort(v1.begin(), v1.end());     for (int i = 0; i <= n; i++) {       long long rad1 = v1[i].first, rad2 = 0, itr = 1;       while (rad1 == v1[i + itr].first) itr++;       for (int j = i + itr; j <= n; j++) {         a = v1[j].second.first;         b = v1[j].second.second;         d2 = (y2 - b) * (y2 - b) + (x2 - a) * (x2 - a);         rad2 = max(rad2, d2);       }       ans = min(rad1 + rad2, ans);     }     cout << ans << endl;     return 0;   }
#include<bits/stdc++.h>   #define ll long long   using namespace std;      int k;   int dfs(int v, int p, vector<vector<int>> &viz){    int t=-1;    vector < int > pos;    for(auto u: viz[v]){     if(u==p) continue;     int w=dfs(u,v,viz);     pos.push_back(w);     if(t==-1) t=w+1;     t = min(t,w+1);    }    sort(pos.begin(), pos.end());    int n = pos.size();    if(v==1){     if(n>=1) k = max(k, pos[n-1]+1);     if(n>=2) k = max(k, pos[n-2]+2);    }    else{     if(n>=2) k = max(k, pos[n-1]+2);    }    if(t==-1) t=0;    return t;   }      int main(){    ios::sync_with_stdio(false);      cin.tie(0);      int t;      cin >> t;      while(t--){       int n;       cin >> n;       k=0;       vector < vector <int> > viz(n+1);       for(int i=0; i<n-1; i++){        int a, b;        cin >> a >> b;        viz[a].push_back(b);        viz[b].push_back(a);     }     dfs(1,0,viz);     cout << k << endl;    }   }
#include <bits/stdc++.h>   using namespace std;   const long double eps = 1e-9;   const long double pi = acos(-1.0);   const long long inf = 1e+9;   #pragma comment(linker,  /STACK:36777216 )   template <typename T>   istream &operator>>(istream &, vector<T> &);   template <typename T>   ostream &operator<<(ostream &, const vector<T> &);   long long s, x;   int bit(long long x, int pos) { return (x & (1LL << pos)) > 0; }   void solve() {     cin >> s >> x;     int l = 45;     while (bit(s, l) == 0) l--;     vector<vector<long long> > dp(l + 2, vector<long long>(2, 0));     dp[0][0] = 1;     for (int i = 1; i <= l + 1; i++) {       int bs = bit(s, i - 1);       int bx = bit(x, i - 1);       if (bs == 0) {         if (bx == 0) {           dp[i][0] = dp[i - 1][0];           dp[i][1] = dp[i - 1][0];         } else {           dp[i][1] += 2 * dp[i - 1][1];         }       } else {         if (bx == 0) {           dp[i][0] = dp[i - 1][1];           dp[i][1] = dp[i - 1][1];         } else {           dp[i][0] += 2 * dp[i - 1][0];         }       }     }     long long ans = dp[l + 1][0];     if (x > s) ans = 0;     if (x == 0) {       if (s % 2 == 0)         ans = 1;       else         ans = 0;     }     if (x == s) ans -= 2;     cout << ans << endl;   }   int main() {     solve();     return 0;   }   template <typename T>   istream &operator>>(istream &is, vector<T> &v) {     for (int i = 0; i < v.size(); ++i) is >> v[i];     return is;   }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     for (int i = 0; i < v.size(); ++i) os << v[i];     return os;   }
#include <bits/stdc++.h>   using namespace std;   long long mc[1 << 20];   list<int> th;   struct f {     long long x, k, m, ms[20];   } fs[100];   bool kcomp(f a, f b) { return a.k < b.k; }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, m, b;     cin >> n >> m >> b;     for (int i = 0; i < n; i++) {       cin >> fs[i].x >> fs[i].k >> fs[i].m;       for (int j = 0; j < fs[i].m; j++) {         cin >> fs[i].ms[j];         fs[i].ms[j]--;       }     }     sort(fs, fs + n, kcomp);     long long bst = -1;     fill_n(mc, 1 << 20, -1);     for (int i = 0; i < n; i++) {       int tbt = 0;       for (int mi = 0; mi < fs[i].m; mi++) {         tbt |= 1 << fs[i].ms[mi];       }       int old = mc[tbt];       mc[tbt] = mc[tbt] == -1 ? fs[i].x : min(mc[tbt], fs[i].x);       if (old == mc[tbt]) continue;       th.push_front(tbt);       auto it = th.begin();       auto pe = th.end();       {         auto it2 = it;         ++it2;         for (; it2 != pe; ++it2) {           int bt = *it | *it2;           if (mc[bt] == -1) th.push_back(bt);           mc[bt] =               mc[bt] == -1 ? mc[*it] + mc[*it2] : min(mc[bt], mc[*it] + mc[*it2]);         }       }       for (int cpos = 0; it != th.end(); ++it, ++cpos) {         auto it2 = pe;         auto ce = th.end();         for (; it2 != ce; ++it2) {           int bt = *it | *it2;           if (mc[bt] == -1) th.push_back(bt);           mc[bt] =               mc[bt] == -1 ? mc[*it] + mc[*it2] : min(mc[bt], mc[*it] + mc[*it2]);         }       }       if (mc[(1 << m) - 1] != -1) {         bst = bst == -1 ? mc[(1 << m) - 1] + b * fs[i].k                         : min(bst, mc[(1 << m) - 1] + b * fs[i].k);       }     }     cout << bst <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   char s[10];   int v[10][10];   int dx[4] = {-2, -2, 2, 2}, dy[4] = {2, -2, 2, -2};   int sx, sy, ex, ey;   int mark[10][10];   int ans;   void dfs(int curx, int cury, int curnum) {     for (int i = 0; i < 4; i++) {       int tempx = curx + dx[i];       int tempy = cury + dy[i];       if (tempx >= 1 && tempx <= 8 && tempy >= 1 && tempy <= 8 &&           !mark[tempx][tempy]) {         mark[tempx][tempy] = curnum + 1;         dfs(tempx, tempy, curnum + 1);       }     }   }   int const nMax = 1;   int main() {     int t;     scanf( %d , &t);     while (t--) {       sx = -1;       memset(mark, 0, sizeof(mark));       memset(v, 0, sizeof(v));       getchar();       for (int i = 1; i <= 8; i++) {         gets(s);         for (int j = 0; j < 8; j++) {           if (s[j] ==  # )             v[i][j + 1] = -1;           else if (s[j] ==  . ) {             v[i][j + 1] = 0;           } else {             v[i][j + 1] = 0;             if (sx != -1) {               ex = i;               ey = j + 1;             } else {               sx = i;               sy = j + 1;             }           }         }       }       if (abs(sx - ex) % 2 != 0 || abs(sy - ey) % 2 != 0) {         puts( NO );         continue;       }       dfs(sx, sy, 0);       if (mark[ex][ey] % 2 == 0 && mark[ex][ey] != 0)         puts( YES );       else         puts( NO );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int report[105], folder[105];   int main() {     int n;     cin >> n;     int k = 1, am = 0;     for (int i = 1; i <= n; i++) cin >> report[i];     for (int i = 1; i <= n; i++) {       if (report[i] < 0 && am == 2) {         k++;         folder[k]++;         am = 1;       } else {         folder[k]++;         if (report[i] < 0) am++;       }     }     cout << k << endl;     for (int i = 1; i <= k; i++) cout << folder[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   string a;   vector<pair<int, int> > v;   void input() {     cin >> a;     n = a.size();   }   void solve() {     int i;     for (i = 0; i < n; i++) {       if (a[i] !=  a ) {         v.push_back(make_pair((a[i] -  a ), i));       }     }     int sz = v.size();     if (sz == 0) {       cout << a <<   n ;       return;     }     if ((sz % 2) != 0) {       cout <<  :( n ;       return;     }     int half = (sz / 2);     for (i = 0; i < half; i++) {       if (v[i].first != v[i + half].first) {         cout <<  :( n ;         return;       }     }     int st_id = v[half].second;     for (i = st_id; i < n; i++) {       if (a[i] ==  a ) {         cout <<  :( n ;         return;       }     }     for (i = 0; i < st_id; i++) {       cout << a[i];     }     cout <<   n ;   }   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     input();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> vec[10];   vector<vector<int> > vvv(183);   queue<int> qu;   map<string, int> mp;   map<string, int>::iterator iter;   bool ch[10] = {false};   int main() {     string s1, s2;     cin >> s1 >> s2;     for (int i = 0; i < s1.length(); i++) {       if (s1[i] >= s2[i])         s1[i] = s2[i];       else {         cout << -1 << endl;         return 0;       }     }     cout << s1 << endl;     return 0;   }
#include <bits/stdc++.h>   int freq[1005] = {0};   int find_int(int a, int b, int c, int d) {     int i;     if (b < c) return 0;     if (a > d) return 0;     if (a <= c && b >= d) {       for (i = c; i <= d; i++) freq[i] = 1;       return d - c + 1;     } else if (a >= c && b <= d) {       for (i = a; i <= b; i++) freq[i] = 1;       return b - a + 1;     } else if (a >= c && b >= d) {       for (i = a; i <= d; i++) freq[i] = 1;       return d - a + 1;     } else if (a <= c && b <= d) {       for (i = c; i <= b; i++) freq[i] = 1;       return b - c + 1;     }   }   int main() {     int i, j, k, l, r, p, q, a[55], b[55], c[55], d[55];     scanf( %d %d %d %d , &p, &q, &l, &r);     for (i = 0; i < p; i++) scanf( %d %d , &a[i], &b[i]);     for (i = 0; i < q; i++) scanf( %d %d , &c[i], &d[i]);     int count = 0;     for (i = 0; i < q; i++) {       for (j = 0; j < p; j++) {         int l1, r1;         if (c[i] >= a[j] && c[i] <= b[j]) l1 = 0;         r1 = b[j] - c[i];         if (c[i] < a[j]) {           l1 = a[j] - d[i];           r1 = b[j] - c[i];         }         count = count + find_int(l1, r1, l, r);       }     }     count = 0;     for (i = l; i <= r; i++) {       if (freq[i] == 1) count++;     }     printf( %d n , count);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void Boost() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   const long double eps = 1e-10;   int main() {     Boost();     int n;     cin >> n;     vector<long double> A(n), B(n);     for (auto &x : A) cin >> x;     for (auto &x : B) cin >> x;     long double lo = 0;     long double hi = 1000000000;     long double best = 0;     while (hi - lo > eps) {       long double mid = (lo + hi) / 2.0;       pair<long double, long double> inter = {A[0] - mid * B[0],                                               A[0] + mid * B[0]};       for (int i = 1; i < n; ++i) {         pair<long double, long double> temp = {A[i] - mid * B[i],                                                A[i] + mid * B[i]};         inter.first = max(inter.first, temp.first);         inter.second = min(inter.second, temp.second);       }       if (inter.first <= inter.second) {         best = mid;         hi = mid;       } else {         lo = mid;       }     }     cout << fixed << setprecision(10) << best;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x;     long long score, sum = 0;     cin >> n;     vector<int> ara(n);     for (int i = 0; i < n; i++) {       cin >> ara[i];       sum += ara[i];     }     sort(ara.begin(), ara.end());     reverse(ara.begin(), ara.end());     score = sum;     for (int i = n - 1; i >= 0; i--) {       sum -= ara[i];       score += (ara[i] + sum);     }     score -= ara[0];     cout << score << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long n = 0, m = 0, mn = 0, mx = 0, l = 1, r = 0, k = 0, j = 1, i = 0,               ans = 0;     cin >> n;     vector<int> a(n);     for (auto &x : a) cin >> x;     bool got = true;     while (got) {       while (i < l) {         if (a[i] > l) {           l = a[i];         }         i++;       }       l = i + 1;       m++;       if (l == n + 1) {         break;       }     }     cout << m << endl;   }
#include <bits/stdc++.h>   using namespace std;   set<int> st;   set<int> en;   vector<int> out;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int t;       cin >> t;       if (st.find(t) == st.end())         st.insert(t);       else if (en.find(t) == en.end())         en.insert(t);     }     int ma = 0;     for (set<int>::iterator it = st.begin(); it != st.end(); it++) {       out.push_back(*it);       ma = max(ma, (*it));     }     for (set<int>::reverse_iterator it = en.rbegin(); it != en.rend(); it++)       if ((*it) != ma) out.push_back(*it);     cout << out.size() << endl;     for (int i = 0; i < out.size(); i++) cout << out[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   int const MAXN = 2e5 + 10;   int n, m, T;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m;     int t = 0;     while (m) {       t = 10 * t + m % 10;       m /= 10;     }     cout << n + t;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   const int32_t M = 1e9 + 7;   const int32_t MM = 998244353;   void solve() {     long long x;     cin >> x;     long long n = 2;     long long tot = (n * (n - 1)) / 2;     long long ans = 0;     while (tot <= x) {       ans++;       n *= 2;       tot += (n * (n - 1)) / 2;     }     cout << ans << endl;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000010, P = 2000010;   int f[P];   int n, t, a[N];   int d[N], g[N], r[P];   vector<int> q[P], v[N];   void init(int c, int p) {     vector<int> z;     int cv = a[c];     d[c] = d[p] + 1;     g[c] = -1;     if (c == 1) fill(r + 1, r + P, -1);     for (int i = 0; i < q[cv].size(); i++) {       int t = q[cv][i];       if (g[c] == -1 || d[r[t]] > d[g[c]]) g[c] = r[t];       z.push_back(r[t]);       r[t] = c;     }     for (int i = 0; i < v[c].size(); i++)       if (v[c][i] != p) init(v[c][i], c);     for (int i = 0; i < q[cv].size(); i++) r[q[cv][i]] = z[i];   }   int main() {     scanf( %d %d , &n, &t);     for (int i = 2; i < P; i++)       if (!f[i])         for (int j = 1; i * j < P; j++) f[i * j] = i;     for (int i = 2; i < P; i++) {       int c = i / f[i];       if (f[c] != f[i]) q[i].push_back(f[i]);       for (int j = 0; j < q[c].size(); j++) q[i].push_back(q[c][j]);     }     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d %d , &x, &y);       v[x].push_back(y);       v[y].push_back(x);     }     init(1, 0);     while (t--) {       int k;       scanf( %d , &k);       if (k == 1) {         int c;         scanf( %d , &c);         printf( %d n , g[c]);       } else {         int x, y;         scanf( %d %d , &x, &y);         a[x] = y;         init(1, 0);       }     }     return 0;   }