malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int fastMax(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; }   int fastMin(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; }   const long long int MAXN = 1e5 + 3;   long long int dp[20][2][10][10];   vector<long long int> digits;   void convert_to_digits(long long int n) {     digits.clear();     if (n == 0) digits.push_back(0);     while (n > 0) {       digits.push_back(n % 10);       n = n / 10;     }   }   long long int recursion(long long int idx, bool flag, long long int first,                           long long int last) {     if (idx == -1) {       if (first == last && first != 0) return 1;       return 0;     }     if (dp[idx][flag][first][last] != -1) return dp[idx][flag][first][last];     long long int ans = 0;     long long int n = (flag) ? digits[idx] : 9;     for (int i = (0); i <= (n); ++i) {       bool nflag = (i == n) ? flag : 0;       long long int nfirst = (first == 0 and i != 0) ? i : first;       long long int nlast = i;       ans = ans + recursion(idx - 1, nflag, nfirst, nlast);     }     return dp[idx][flag][first][last] = ans;   }   void solve() {     long long int l, r;     cin >> l >> r;     memset(dp, -1, sizeof(dp));     convert_to_digits(r);     long long int ans = recursion(digits.size() - 1, 1, 0, 0);     memset(dp, -1, sizeof(dp));     if (l > 1) {       convert_to_digits(l - 1);       ans -= recursion(digits.size() - 1, 1, 0, 0);     }     cout << ans << endl;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long int t;     t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = (int)2 * 1e5 + 10;   void solve() {     long long n, m;     cin >> n >> m;     vector<long long> arr(n);     for (long long i = 0; i < n; i += 1) {       cin >> arr[i];     }     sort((arr).begin(), (arr).end());     long long sum = 0;     for (long long i = 0; i < m; i++) {       if (arr[i] < 0) {         sum += arr[i];       }     }     cout << abs(sum) <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     solve();     return 0;   }
#include<bits/stdc++.h>   using namespace std;   const int P=1e9+7,N=209,iv=P+1>>1;   int f[N][N],ans[N][N],d[N],sz[N],fa[N];   basic_string<int>g[N];   void dfs(int x,int y){    sz[x]=1,fa[x]=y;    for(int i:g[x])if(i!=y)d[i]=d[x]+1,dfs(i,x),sz[x]+=sz[i];   }   int qp(int a,int b){    int r=1;    for(;b;b>>=1,a=a*1ll*a%P)if(b&1)r=r*1ll*a%P;    return r;   }   int main(){    int n,i,j,k,u,w=0,o;    scanf( %d ,&n);    for(i=1;i<=n;++i){     memset(f,0,sizeof f);     for(j=1;j<i;++j)f[0][j]=1,f[j][i+1]=0;     for(j=1;j<i;++j)for(k=i-1;k>=j;--k)f[j][k]=(f[j-1][k]+f[j][k+1])*1ll*iv%P;     for(j=1;j<i;++j)ans[i][j]=f[j][j];     ans[i][0]=1;    }    for(i=1;i<n;++i)scanf( %d%d ,&j,&k),g[j]+=k,g[k]+=j;    for(i=1;i<=n;++i){     d[i]=0,dfs(i,0);     for(j=1;j<i;++j){      u=d[j],k=j,o=sz[j];      while(1){       k=fa[k];       w=(w+(sz[k]-o)*1ll*ans[u][d[k]])%P;       o=sz[k];       if(k==i)break;      }     }    }    printf( %lld ,w*1ll*qp(n,P-2)%P);    return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e6 + 9, N = 1e3 + 9;   const int qwer[] = {-1, 0, 1, 0}, asdf[] = {0, 1, 0, -1};   int n, m, a[N][N], arr[MAX], sizee[MAX], number, c[N][N], vv, cnt;   long long k;   struct node {     int id, x, y;   } b[MAX];   int root(int x) { return x == arr[x] ? x : arr[x] = root(arr[x]); }   void merge(int x, int y) {     int zxcv = root(x), fy = root(y);     if (sizee[zxcv] < sizee[fy]) swap(zxcv, fy);     if (zxcv == fy) return;     arr[fy] = zxcv;     sizee[zxcv] += sizee[fy];   }   bool cmp(const node& x, const node& y) { return x.id > y.id; }   void dfs(int x, int y) {     if (c[x][y]) return;     if (number)       c[x][y] = vv, number--;     else       return;     for (int i = 0; i < 4; i++) {       int nx = x + qwer[i];       int ny = y + asdf[i];       if (nx < 1 || nx > n || ny < 1 || ny > m) continue;       if (a[nx][ny] < vv) continue;       dfs(nx, ny);     }   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> m >> k;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         cin >> a[i][j], cnt++, b[cnt].x = i, b[cnt].y = j, b[cnt].id = a[i][j];     sort(b + 1, b + cnt + 1, cmp);     for (int i = 1; i <= cnt; i++) arr[i] = i, sizee[i] = 1;     int i;     for (i = 1; i <= cnt; i++) {       int dd = (b[i].x - 1) * m + b[i].y;       for (int j = 0; j < 4; j++) {         int nx = b[i].x + qwer[j];         int ny = b[i].y + asdf[j];         if (nx < 1 || nx > n || ny < 1 || ny > m || a[nx][ny] < b[i].id) continue;         merge(dd, (nx - 1) * m + ny);       }       if (k % b[i].id == 0 && sizee[root(dd)] >= k / b[i].id) break;     }     if (i > cnt) return cout <<  NO , 0;     vv = b[i].id, number = k / b[i].id, dfs(b[i].x, b[i].y);     cout <<  YES n ;     for (int i = 1; i <= n; i++, cout <<   n )       for (int j = 1; j <= m; j++) cout << c[i][j] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long Readint() {     long long ret = 0;     int f = 1;     char ch;     do {       ch = getchar();       if (ch ==  - ) f *= -1;     } while (ch >= 0 && (ch <  0  || ch >  9 ));     while ( 0  <= ch && ch <=  9 ) {       ret = ret * 10 + ch -  0 ;       ch = getchar();     }     return ret * f;   }   void open() {     freopen( E.in ,  r , stdin);     freopen( E.out ,  w , stdout);   }   void close() {     fclose(stdin);     fclose(stdout);   }   const int MAXN = 101010;   set<int> sp[2];   char s[MAXN];   vector<int> ans;   int n;   void init() {     int cntl = 0, cntr = 0;     scanf( %s , s + 1);     n = strlen(s + 1);     for (int i = 1, _END_ = n; i <= _END_; i++)       if (s[i] ==  L )         cntl++;       else         cntr++;     if (cntl < cntr || (cntl == cntr && s[1] ==  R )) {       for (int i = 1, _END_ = n; i <= _END_; i++)         if (s[i] ==  L )           s[i] =  R ;         else           s[i] =  L ;     }     for (int i = 1, _END_ = n; i <= _END_; i++)       if (s[i] ==  L )         sp[0].insert(i);       else         sp[1].insert(i);   }   void work() {     int type = 0;     set<int>::iterator now;     int num = 0;     int tot = 0;     now = sp[0].begin();     num = *now;     sp[0].erase(now);     for (int i = 1, _END_ = n; i < _END_; i++) {       ans.push_back(num);       now = sp[type ^ 1].lower_bound(num);       if (now == sp[type ^ 1].end()) {         tot++;         now = sp[type ^ 1].begin();         num = *now;         sp[type ^ 1].erase(num);         type ^= 1;       } else {         if (sp[type].lower_bound(*now) == sp[type].end()) {           int mn = 0x3f3f3f3f;           if (sp[0].begin() != sp[0].end()) mn = min(mn, *sp[0].begin());           if (sp[1].begin() != sp[1].end()) mn = min(mn, *sp[1].begin());           if (mn < num && s[mn] != s[num]) {             tot++;             num = mn;             sp[type ^ 1].erase(num);             type ^= 1;             continue;           }         }         num = *now;         sp[type ^ 1].erase(num);         type ^= 1;       }     }     ans.push_back(num);     printf( %d n , tot);     for (int i = 0, _END_ = ans.size(); i < _END_; i++) printf( %d  , ans[i]);   }   int main() {     int _ = 0;     init();     work();     close();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   long long k, a[500005];   int chack1(int x) {     long long k1 = 0, c = 0;     for (int i = 0; i < n; i++) {       if (a[i] > x)         k1 += (a[i] - x);       else         c += (x - a[i]);     }     if (k1 <= k && c >= k1)       return 1;     else       return 0;   }   int chack2(int x) {     long long k2 = 0, c1 = 0;     for (int i = 0; i < n; i++) {       if (a[i] < x)         k2 += (x - a[i]);       else         c1 += (a[i] - x);     }     if (k2 <= k && c1 >= k2)       return 1;     else       return 0;   }   int main() {     while (cin >> n >> k) {       for (int i = 0; i < n; i++) cin >> a[i];       sort(a, a + n);       int max = a[n - 1], min = a[0];       int low = min, high = max;       while (low <= high) {         int mid = (low + high) / 2;         long long k1 = 0, c = 0;         if (chack1(mid))           high = mid - 1, max = mid;         else           low = mid + 1;       }       low = 0, high = a[n - 1];       while (low <= high) {         int mid = (low + high) / 2;         if (chack2(mid))           low = mid + 1, min = mid;         else           high = mid - 1;       }       cout << max - min << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXM = 101000;   pair<int, int> a[MAXM];   vector<pair<int, int> > b[MAXM << 1];   vector<int> c[MAXM << 1], d[MAXM << 1];   int main() {     int n, m, i, j, k, x, y;     int f, l, r, top;     while (scanf( %d%d , &n, &m) != EOF) {       for (i = 0; i < m; i++) {         scanf( %d%d , &x, &y);         a[i] = make_pair(x, y);       }       sort(a, a + m);       for (i = 0; i + n - 1 < m; i++)         if (a[i].first == a[i + n - 1].first) break;       if (i + n - 1 < m && a[i].first == a[i + n - 1].first) {         puts( -1 );         continue;       }       if (a[0].first == 1) {         b[0].push_back(make_pair(1, a[0].second - 1));         f = 1;         top = 0;       } else {         b[0].push_back(make_pair(1, n));         b[1].push_back(make_pair(1, a[0].second - 1));         f = a[0].first;         top = 1;       }       for (i = 1; i < m; i++) {         if (a[i].first > f) {           if (a[i - 1].second != n)             b[top].push_back(make_pair(a[i - 1].second + 1, n));           top++;           if (a[i].first - f > 1) b[top++].push_back(make_pair(1, n));           if (a[i].second > 1) b[top].push_back(make_pair(1, a[i].second - 1));           f = a[i].first;         } else {           if (a[i].second - a[i - 1].second > 1)             b[top].push_back(make_pair(a[i - 1].second + 1, a[i].second - 1));         }       }       if (a[m - 1].second != n)         b[top].push_back(make_pair(a[m - 1].second + 1, n));       top++;       if (a[m - 1].first != n) b[top++].push_back(make_pair(1, n));       c[0].push_back(b[0][0].first);       d[0].push_back(b[0][0].second);       for (i = 1; i < top; i++) {         f = b[i].size();         for (j = 0; j < f; j++) {           k = lower_bound(d[i - 1].begin(), d[i - 1].end(), b[i][j].first) -               d[i - 1].begin();           if (k >= 0 && k < d[i - 1].size() && d[i - 1][k] >= b[i][j].first &&               c[i - 1][k] <= b[i][j].second) {             c[i].push_back(max(b[i][j].first, c[i - 1][k]));             d[i].push_back(b[i][j].second);           }         }         if (c[i].size() == 0) break;       }       if (d[top - 1].size() != 0 && d[top - 1][d[top - 1].size() - 1] == n)         printf( %d n , 2 * n - 2);       else         puts( -1 );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000000 + 7;   int n, bas, lim;   int go[210][22];   int trie[210][22], tn;   int upper[210], lower[210], val[210], str[210];   int fail[210];   int bound[210];   int f[2][210][210][510];   queue<int> q;   inline int min(int a, int b) { return a < b ? a : b; }   int work() {     int p = 200;     while (p >= 0 && !bound[p]) {       --p;     }     if (p < 0) return 0;     memset(f, 0, sizeof(f));     f[0][0][0][0] = 1;     int ans = 0;     for (int i = 0; i <= p; i++) {       for (int j = 0; j <= tn; j++) {         for (int k = 0; k < 2; k++) {           for (int v = 0; v <= lim; v++) {             if (!f[k][i][j][v]) continue;             for (int fil = 0; fil < bas; fil++) {               int& nxt = f[(fil == bound[i] && k) || fil > bound[i]][i + 1]                           [go[j][fil]][min(lim + 1, v + val[go[j][fil]])];               nxt += f[k][i][j][v];               if (nxt >= MOD) nxt -= MOD;               if (fil && v + val[go[j][fil]] <= lim &&                   (!((fil == bound[i] && k) || fil > bound[i]) || i < p)) {                 ans += f[k][i][j][v];                 if (ans >= MOD) ans -= MOD;               }             }           }         }       }     }     return ans;   }   void mminus() {     for (int i = 0; i <= 200; i++) {       --bound[i];       if (bound[i] >= 0) break;       bound[i] += bas;     }   }   int main() {     scanf( %d%d%d , &n, &bas, &lim);     int len, lenl, lenr;     scanf( %d , &lenl);     for (int i = lenl - 1; i >= 0; i--) scanf( %d , lower + i);     scanf( %d , &lenr);     for (int i = lenr - 1; i >= 0; i--) scanf( %d , upper + i);     while (n--) {       scanf( %d , &len);       for (int i = len; i >= 1; i--) scanf( %d , str + i);       int cur = 0;       for (int i = 1; i <= len; i++) {         if (!trie[cur][str[i]]) trie[cur][str[i]] = ++tn;         cur = trie[cur][str[i]];       }       int v;       scanf( %d , &v);       val[cur] += v;     }     q.push(0);     while (!q.empty()) {       int cur = q.front();       q.pop();       for (int i = 0; i < bas; i++) {         if (trie[cur][i]) {           go[cur][i] = trie[cur][i];           int ff;           for (ff = fail[cur]; ff && !trie[ff][i]; ff = fail[ff])             ;           if (ff == cur)             fail[trie[cur][i]] = 0;           else             fail[trie[cur][i]] = trie[ff][i];           val[trie[cur][i]] += val[fail[trie[cur][i]]];           q.push(trie[cur][i]);         } else {           int ff;           for (ff = fail[cur]; ff && !trie[ff][i]; ff = fail[ff])             ;           go[cur][i] = trie[ff][i];         }       }     }     for (int i = 200; i >= 0; i--) bound[i] = upper[i];     int ans = work();     for (int i = 200; i >= 0; i--) bound[i] = lower[i];     mminus();     ans -= work();     if (ans < 0) ans += MOD;     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline ostream &operator<<(ostream &_out, const vector<T> &_v) {     if (_v.empty()) return _out;     _out << _v.front();     for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) _out <<     << *_it;     return _out;   }   template <typename T>   inline istream &operator>>(istream &_in, vector<T> &_v) {     for (auto &_i : _v) _in >> _i;     return _in;   }   template <typename T>   inline ostream &operator<<(ostream &_out, const set<T> &_s) {     if (_s.empty()) return _out;     _out << *_s.begin();     for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out <<     << *_it;     return _out;   }   template <typename T, typename U>   inline ostream &operator<<(ostream &_out, const map<T, U> &_m) {     if (_m.empty()) return _out;     _out <<  (  << _m.begin()->first <<  :   << _m.begin()->second <<  ) ;     for (auto _it = ++_m.begin(); _it != _m.end(); ++_it)       _out <<  , (  << _it->first <<  :   << _it->second <<  ) ;     return _out;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   inline void solve() {     int n;     cin >> n;     vector<int> p(n);     cin >> p;     int begin_of_current_segment = 0;     bool increase = p[1] > p[0];     vector<bool> mask(n, false);     for (int i = 2; i < n; ++i) {       if (p[i] > p[i - 1]) {         if (!increase) {           increase = true;           mask[begin_of_current_segment] = true;           mask[i - 1] = true;           begin_of_current_segment = i - 1;         }       } else {         if (increase) {           increase = false;           mask[begin_of_current_segment] = true;           mask[i - 1] = true;           begin_of_current_segment = i - 1;         }       }     }     mask[begin_of_current_segment] = true;     mask.back() = true;     cout << accumulate(mask.begin(), mask.end(), 0) <<   n ;     for (int i = 0; i < n; ++i) {       if (mask[i]) cout << p[i] <<    ;     }     cout <<   n ;   }   inline void tsolve() {     int t;     cin >> t;     while (t--) solve();   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     tsolve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   char s[1000111];   pair<int, int> q[33];   int a[33];   int main() {     scanf( %d%d n , &n, &k);     gets(s);     int l = strlen(s);     for (int i = 0; i < k; i++) q[i].second = i;     long long sum = 1;     for (int i = 0; i < l; i++) {       int u = s[i] -  a ;       q[u].first = i + 1;       long long t = (sum - a[u] + 1000000007) % 1000000007;       sum = (sum + t) % 1000000007;       a[u] = (a[u] + t) % 1000000007;     }     sort(q, q + k);     for (int i = 0; i < n; i++) {       int u = q[i % k].second;       long long t = (sum - a[u] + 1000000007) % 1000000007;       sum = (sum + t) % 1000000007;       a[u] = (a[u] + t) % 1000000007;     }     cout << sum << endl;     return 0;   }
#include <bits/stdc++.h>   const int N = 500005, M = 105, INF = 0x3f3f3f3f;   int n, K, p, sum[N], f[M][N], t[105], g[N];   void solveC2() {     for (int i = 1; i <= n; i++) f[0][i] = INF;     for (int i = 1; i <= K; i++) {       for (int j = 0; j < p; j++) t[j] = INF;       if (i == 1) t[0] = 0;       for (int j = 1; j <= n; j++) {         f[i][j] = INF;         for (int k = 0; k < p; k++)           f[i][j] = std::min(f[i][j], t[k] + (sum[j] - k + p) % p);         t[sum[j]] = std::min(t[sum[j]], f[i - 1][j]);       }     }     printf( %d , f[K][n]);   }   void solveC3() {     memset(g, 0x3f, sizeof g);     for (int i = 1; i < n; i++)       *std::upper_bound(g + 1, g + 1 + n, sum[i]) = sum[i];     if (g[K - 1] <= sum[n])       printf( %d , sum[n]);     else       printf( %d , sum[n] + p);   }   int main() {     scanf( %d%d%d , &n, &K, &p);     for (int i = 1; i <= n; i++)       scanf( %d , &sum[i]), sum[i] = (sum[i] + sum[i - 1]) % p;     if (K * p > n)       solveC2();     else       solveC3();     return 0;   }
#include <bits/stdc++.h>   const int oo = 0x7fffffff;   const long long OO = 0x7fffffffffffffff;   template <class T>   std::ostream& operator<<(std::ostream& O, const std::vector<T>& V) {     for (const T& x : V) O << x <<    ;     O <<   n ;     return O;   }   template <class T1, class T2>   std::ostream& operator<<(std::ostream& O, const std::pair<T1, T2>& P) {     return O <<  (  << P.first <<  ,   << P.second <<  ) ;   }   std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());   using namespace std;   int main() {     long double y1, y2, yw, xb, yb, r;     cin >> y1 >> y2 >> yw >> xb >> yb >> r;     yw -= r, y1 += r;     long double a = atan2(xb, (yw - yb) + (yw - y1));     long double dr = (y2 - y1) * sin(a);     if (dr < r)       cout <<  -1 n ;     else {       long double xw = (yw - y1) * xb / (yw - yb + yw - y1);       cout.precision(10);       cout << fixed << xw <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s1[100002], s2[100002];   int diff[100002] = {0};   int main() {     scanf( %s , s1);     scanf( %s , s2);     int i, len = strlen(s1), count = 0, temp;     for (i = 0; i < len; i++) {       if (s1[i] != s2[i]) {         diff[i] = 1;         count++;       }     }     if (count & 1)       cout <<  impossible ;     else {       temp = count >> 1;       for (i = 0; i < len; i++) {         printf( %c , s1[i]);         if (s1[i] != s2[i]) temp--;         if (temp == 0) break;       }       i++;       for (; i < len; i++) printf( %c , s2[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 151;   const int inf = 0x7f7f7f7f;   const int mod = (int)(1e9 + 7);   const long long INF = 0x7f7f7f7f7f7f7f7fLL;   const double eps = 1e-8;   const double pi = acos(-1.0);   const int mask = 65535;   int a[maxn];   int b[maxn];   void handle(int a[], int n) {     if (n == 1) {       a[0] = 1;       return;     }     if (n == 2) {       a[0] = 3;       a[1] = 4;       return;     }     if (n & 1) {       std::fill(a, a + maxn, 1);       a[0] = 2;       a[n - 1] = (n + 1) >> 1;     } else {       std::fill(a, a + maxn, 1);       a[n - 1] = (n - 1) >> 1;     }   }   int main() {     ios::sync_with_stdio(false);     int n, m;     int i, j;     cin >> n >> m;     handle(a, n);     handle(b, m);     for (i = 0; i < n; ++i) {       for (j = 0; j < m; ++j) {         if (j) cout <<    ;         cout << a[i] * b[j];       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int N = 4e2 + 5;   int n, f[N][N];   int main() {     scanf( %d , &n);     f[1][0] = f[1][1] = 1;     for (int top = 1; top < n; ++top) {       for (int i = 0; i <= n; ++i) {         for (int j = 0; j <= n - i + 1; ++j) {           int tmp = (long long)f[top][i] * f[top][j] % MOD;           if (i + j <= n)             f[top + 1][i + j] =                 (f[top + 1][i + j] + (long long)(2 * i + 2 * j + 1) * tmp % MOD) %                 MOD;           if (i + j + 1 <= n)             f[top + 1][i + j + 1] = (f[top + 1][i + j + 1] + tmp) % MOD;           if (i + j - 1 <= n)             f[top + 1][i + j - 1] =                 (f[top + 1][i + j - 1] +                  (long long)(i + j - 1) * (i + j) % MOD * tmp % MOD) %                 MOD;         }       }     }     printf( %d n , f[n][1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200005;   int n, m;   char s[maxn];   long long ans[maxn];   int sz[maxn];   int cnt[1 << 20];   vector<int> g[maxn];   bool die[maxn];   int getsz(int x, int f) {     sz[x] = 1;     for (int y : g[x])       if (y != f && !die[y]) sz[x] += getsz(y, x);     return sz[x];   }   int getrt(int tot, int x, int f) {     for (int y : g[x])       if (y != f && !die[y])         if (sz[y] * 2 >= tot) return getrt(tot, y, x);     return x;   }   int h(int x) { return 1 << (s[x] -  a ); }   void update(int x, int f, int coe, int pre) {     cnt[pre ^= h(x)] += coe;     for (int y : g[x])       if (y != f && !die[y]) update(y, x, coe, pre);   }   long long query(int x, int f, int pre) {     long long pass = cnt[pre ^= h(x)];     for (int i = 0; i < 20; i++) pass += cnt[pre ^ (1 << i)];     for (int y : g[x])       if (y != f && !die[y]) pass += query(y, x, pre);     ans[x] += pass;     return pass;   }   void solve(int x) {     die[x] = 1;     update(x, 0, 1, h(x));     long long pass = cnt[h(x)];     for (int i = 0; i < 20; i++) pass += cnt[(1 << i) ^ h(x)];     for (int y : g[x])       if (!die[y]) {         update(y, x, -1, 0);         pass += query(y, x, h(x));         update(y, x, 1, 0);       }     update(x, 0, -1, h(x));     ans[x] += pass / 2 + 1;     for (int y : g[x])       if (!die[y]) solve(getrt(getsz(y, x), y, x));   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d%d , &u, &v);       g[u].push_back(v);       g[v].push_back(u);     }     scanf( %s , s + 1);     solve(getrt(getsz(1, 0), 1, 0));     for (int i = 1; i <= n; i++) printf( %lld  , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     scanf( %d , &T);     while (T--) {       int n, a, o;       vector<pair<pair<int, int>, int> > M;       scanf( %d , &n);       M.push_back(make_pair(make_pair(0, 0), 0));       for (int i = 1; i <= n * 2 - 1; i++) {         scanf( %d%d , &a, &o);         M.push_back(make_pair(make_pair(a, o), i));       }       sort(M.begin(), M.end());       long long s[2] = {0};       for (int i = 1; i <= n * 2 - 1; i++) {         s[i & 1] += M[i].first.second;       }       printf( YES n );       if (s[1] > s[0]) {         for (int i = 1; i <= n * 2 - 1; i += 2) {           printf( %d  , M[i].second);         }       } else {         for (int i = 2; i <= n * 2 - 1; i += 2) {           printf( %d  , M[i].second);         }         printf( %d , M[n * 2 - 1].second);       }       printf(  n );     }   }