malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3f;   const long double pi = acos(-1.0);   const int N = 2e5 + 100;   int tr[4 * N];   int inicial[N];   int v[4 * N];   int n;   void build(int node, int b, int e) {     if (b == e)       tr[node] = b;     else {       int mid = (b + e) / 2;       build(2 * node, b, mid);       build(2 * node + 1, mid + 1, e);       if (v[tr[2 * node]] > v[tr[2 * node + 1]]) {         tr[node] = tr[2 * node + 1];       } else {         tr[node] = tr[2 * node];       }     }   }   void update(int node, int b, int e, int i, int val) {     if (i < b or i > e) return;     if (b == e) {       if (v[b] > val) v[b] = val + 1;       return;     }     int mid = (b + e) / 2;     update(2 * node, b, mid, i, val);     update(2 * node + 1, mid + 1, e, i, val);     if (v[tr[2 * node]] > v[tr[2 * node + 1]]) {       tr[node] = tr[2 * node + 1];     } else {       tr[node] = tr[2 * node];     }   }   int query(int node, int b, int e, int i, int j) {     if (i > e or j < b) return -1;     if (i <= b and j >= e) return tr[node];     int mid = (b + e) / 2;     int p1 = query(2 * node, b, mid, i, j);     int p2 = query(2 * node + 1, mid + 1, e, i, j);     if (p1 == -1) return p2;     if (p2 == -1) return p1;     if (v[p1] < v[p2]) return p1;     return p2;   }   void conserta(int x) {     if (x - 1 >= 1) {       update(1, 1, n, x - 1, v[x]);     }     if (x + 1 <= n) {       update(1, 1, n, x + 1, v[x]);     }   }   void solve(int b, int e) {     if (b > e) return;     int x = query(1, 1, n, b, e);     conserta(x);     solve(b, x - 1);     solve(x + 1, e);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int x, y;       scanf( %d%d , &x, &y);       inicial[i] = x;       v[i] = x + y;     }     build(1, 1, n);     solve(1, n);     long long resp = 0;     bool pau = false;     for (int i = 1; i <= n; i++) {       resp += v[i] - inicial[i];       if (inicial[i] > v[i]) pau = true;     }     if (pau) {       printf( %d n , -1);     } else {       cout << resp << endl;       for (int i = 1; i < n; i++) printf( %d  , v[i]);       printf( %d n , v[n]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, q, w[15];   char s[15];   int cnt[5005];   int sum[5000][105];   int tot2[15];   int main() {     scanf( %d%d%d , &n, &m, &q);     tot2[0] = 1;     for (int i = 1; i <= 14; i++) tot2[i] = tot2[i - 1] * 2;     for (int i = 1; i <= n; i++) scanf( %d , &w[i]);     for (int i = 1; i <= m; i++) {       scanf( %s , s);       int len = strlen(s);       int x = 0;       for (int i = 0; i < len; i++) x = x * 2 + s[i] -  0 ;       cnt[x]++;     }     for (int i = 0; i < tot2[n]; i++) {       for (int j = 0; j < tot2[n]; j++) {         int x = i ^ j;         int tot = 0;         for (int k = 0; k < n; k++) tot += (!((x >> k) & 1)) * w[n - k];         if (tot <= 100) sum[i][tot] += cnt[j];       }     }     for (int i = 0; i < tot2[n]; i++) {       for (int j = 1; j <= 100; j++) {         sum[i][j] += sum[i][j - 1];       }     }     while (q--) {       int x = 0;       char Q[15];       int val;       scanf( %s%d , Q, &val);       for (int i = 0; i < n; i++) x = x * 2 + Q[i] -  0 ;       printf( %d n , sum[x][val]);     }   }
#include <bits/stdc++.h>   using namespace std;   inline void rd(int &x) {     x = 0;     char o, f = 1;     while (o = getchar(), o < 48)       if (o == 45) f = -f;     do x = (x << 3) + (x << 1) + (o ^ 48);     while (o = getchar(), o > 47);     x *= f;   }   int head[100005], to[100005 << 1], nxt[100005 << 1], tot;   inline void add(int a, int b) {     to[++tot] = b;     nxt[tot] = head[a];     head[a] = tot;   }   int n, m, q, a, b, c, tp, ans[100005];   int id[100005], reid[100005], dfsid, sz[100005], son[100005], fa[100005],       top[100005], deep[100005];   void dfs(int x, int f) {     fa[x] = f;     deep[x] = deep[f] + 1;     sz[x] = 1;     for (int i = head[x]; i; i = nxt[i]) {       int y = to[i];       if (y == fa[x]) continue;       dfs(y, x);       sz[x] += sz[y];       if (sz[y] > sz[son[x]]) son[x] = y;     }   }   void chain(int x, int f) {     top[x] = f;     reid[id[x] = ++dfsid] = x;     if (son[x]) chain(son[x], f);     for (int i = head[x]; i; i = nxt[i]) {       int y = to[i];       if (y == fa[x] || y == son[x]) continue;       chain(y, y);     }   }   vector<int> area[100005];   int st[100005 << 2][22];   void build(int p = 1, int l = 1, int r = n) {     if (l == r) {       for (int i = 0, tp = 0; i < area[reid[l]].size() && tp < 10; i++, tp++)         st[p][++st[p][0]] = area[reid[l]][i];       return;     }     int mid = l + r >> 1, x = 0, y = 0;     build(p << 1, l, mid);     build(p << 1 | 1, mid + 1, r);     while (st[p][0] < 10 && x < st[p << 1][0] && y < st[p << 1 | 1][0]) {       if (st[p << 1][x + 1] < st[p << 1 | 1][y + 1])         st[p][++st[p][0]] = st[p << 1][++x];       else         st[p][++st[p][0]] = st[p << 1 | 1][++y];     }     while (st[p][0] < 10 && x < st[p << 1][0])       st[p][++st[p][0]] = st[p << 1][++x];     while (st[p][0] < 10 && y < st[p << 1 | 1][0])       st[p][++st[p][0]] = st[p << 1 | 1][++y];   }   void query(int a, int b, int p = 1, int l = 1, int r = n) {     if (l > b || r < a) return;     if (l >= a && r <= b) {       for (int i = 1; i <= min(st[p][0], c); i++) ans[++ans[0]] = st[p][i];       return;     }     int mid = l + r >> 1;     query(a, b, p << 1, l, mid);     query(a, b, p << 1 | 1, mid + 1, r);   }   int main() {     rd(n), rd(m), rd(q);     for (int i = 1; i < n; i++) {       rd(a), rd(b);       add(a, b);       add(b, a);     }     dfs(1, 0);     chain(1, 1);     for (int i = 1; i <= m; i++) {       rd(a);       area[a].push_back(i);     }     for (int i = 1; i <= n; i++) sort(area[i].begin(), area[i].end());     build();     while (q--) {       ans[0] = 0;       rd(a), rd(b), rd(c);       while (top[a] != top[b]) {         if (deep[top[a]] < deep[top[b]]) swap(a, b);         query(id[top[a]], id[a]);         a = fa[top[a]];       }       if (deep[a] > deep[b]) swap(a, b);       query(id[a], id[b]);       sort(ans + 1, ans + 1 + ans[0]);       printf( %d  , min(c, ans[0]));       for (int i = 1; i <= min(c, ans[0]); i++) printf( %d  , ans[i]);       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9;   const int SIZE = 1e6 + 5;   const long long INF = 1LL << 55;   const double eps = 1e-10;   int d[1000009];   int main() {     int(n);     scanf( %d , &n);     if (n % 2) {       int h = n / 2;       for (int i = 0; i < (h); ++i) {         d[i] = d[n - 2 - i] = 2 * (i + 1);       }       for (int i = 0; i < (h + 1); ++i) {         d[i + n - 1] = d[2 * n - 2 - i] = 2 * i + 1;       }       d[2 * n - 1] = n;     } else {       int h = n / 2;       for (int i = 0; i < (h); ++i) {         d[i] = d[n - 1 - i] = 2 * i + 1;       }       for (int i = 0; i < (h); ++i) {         d[i + n] = d[2 * n - 2 - i] = (2 * (i + 1));       }       d[2 * n - 1] = n;     }     for (int i = 0; i < (2 * n); ++i) printf( %d  , d[i]);   }
#include <bits/stdc++.h>   using namespace std;   const int NMAX = 1000000;   vector<int> graf[1 + NMAX];   int minim[1 + NMAX];   int minimLant = INT_MAX;   bool vizitat[1 + NMAX];   void dfs(int z) {     for (int i = 0; i < graf[z].size(); i++) {       if (!vizitat[graf[z][i]]) {         vizitat[graf[z][i]] = true;         minim[graf[z][i]] = min(minim[z], graf[z][i]);         dfs(graf[z][i]);       }     }   }   int main() {     int n, q;     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n >> q;     for (int i = 1; i <= n - 1; i++) {       int x, y;       cin >> x >> y;       graf[x].emplace_back(y);       graf[y].emplace_back(x);     }     for (int i = 1; i <= n; i++) {       minim[i] = INT_MAX;     }     int t, z;     cin >> t >> z;     z = z % n + 1;     minim[z] = z;     vizitat[z] = true;     dfs(z);     int last = 0;     for (int i = 2; i <= q; i++) {       cin >> t >> z;       z = (z + last) % n + 1;       if (t == 1) {         minimLant = min(minimLant, minim[z]);       } else {         last = min(minimLant, minim[z]);         cout << last <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, q, A[1005], B[1005], x, y;   int main() {     scanf( %d %d , &n, &q);     for (int i = 1; i <= q; i++) {       scanf( %d %d , &x, &y);       A[x] = 1;       B[y] = 1;     }     int cev = 0;     for (int i = 2; i < n; i++) {       cev += !A[i] + !B[i];     }     if (n % 2 == 1 && A[n / 2 + 1] == 0 && B[n / 2 + 1] == 0) cev--;     printf( %d n , cev);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int n, m, p;   long long int a[2105][2105];   long long int sz[2105 * 2105];   long long int fa[2105 * 2105];   pair<long long int, pair<long long int, long long int> > arr[2105 * 2105];   const int mv[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};   long long int find(long long int x) {     return fa[x] == x ? x : fa[x] = find(fa[x]);   }   void merge(long long int a, long long int b) {     a = find(a);     b = find(b);     if (a != b) {       sz[a] += sz[b];       sz[b] = 0;       fa[b] = a;     }   }   long long int out[2105][2105];   long long int height, freq;   void dfs(long long int x, long long int y) {     if (x < 0 || x >= n || y < 0 || y >= m) return;     if (out[x][y]) return;     if (a[x][y] < height) return;     if (!freq) return;     out[x][y] = height;     freq--;     dfs(x + 1, y);     dfs(x - 1, y);     dfs(x, y + 1);     dfs(x, y - 1);     return;   }   int main() {     ios_base::sync_with_stdio(0);     long long int i, j, k;     cin >> n >> m >> p;     for (i = 0; i < (n); ++i)       for (j = 0; j < (m); ++j) {         cin >> a[i][j];         arr[i * m + j] = pair<long long int, pair<long long int, long long int> >(             a[i][j], pair<long long int, long long int>(i, j));       }     for (i = 0; i < (n * m); ++i) {       fa[i] = i;       sz[i] = 1;     }     sort(arr, arr + n * m);     reverse(arr, arr + n * m);     long long int ans = -1;     i = 0;     while (i < n * m) {       j = i;       while (j < n * m && arr[j].first == arr[i].first) {         long long int x0, x, y0, y;         x0 = arr[j].second.first;         y0 = arr[j].second.second;         for (k = 0; k < (4); ++k) {           x = x0 + mv[k][0];           y = y0 + mv[k][1];           if (x >= 0 && x < n && y >= 0 && y < m)             if (a[x][y] >= arr[j].first) merge(x * m + y, x0 * m + y0);         }         j++;       }       if (arr[i].first && (p % arr[i].first) == 0)         for (k = i; k < j; ++k) {           long long int x, y;           x = arr[k].second.first;           y = arr[k].second.second;           if (sz[find(x * m + y)] >= p / arr[i].first) {             ans = x * m + y;             break;           }         }       if (ans != -1) break;       i = j;     }     if (ans == -1) {       cout <<  NO n ;       return 0;     }     cout <<  YES n ;     height = a[ans / m][ans % m];     freq = p / height;     dfs(ans / m, ans % m);     for (i = 0; i < (n); ++i) {       for (j = 0; j < (m); ++j) cout << out[i][j] <<    ;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long int> ans;   vector<long long int> allD;   unordered_map<long long int, int> comp;   const int MM = 1e4;   const int LIM = 1e5;   vector<long long int> gr[MM];   void solve(long long int N, long long int K) {     if (K == 0 || N == 0) {       ans.push_back(N);       return;     }     for (long long int u : gr[N]) {       solve(u, K - 1);       if (ans.size() == LIM) {         return;       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int N, K;     cin >> N >> K;     for (long long int i = 1; i * i <= N; i++) {       if (N % i == 0) {         allD.push_back(i);         if (i * i != N) {           allD.push_back(N / i);         }       }     }     sort(allD.begin(), allD.end());     for (int i = 0; i < allD.size(); i++) {       for (int j = 0; j <= i; j++) {         if (allD[i] % allD[j] == 0) {           gr[i].push_back(j);         }       }     }     K = min(K, (long long int)LIM);     solve(allD.size() - 1, K);     for (auto u : ans) {       cout << allD[u] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;      typedef long long ll;   typedef pair<int, int> pii;   typedef pair<ll, ll> pll;      const int MAXN = 2e5;   const int MAXM = 5e6;      int N;   pii A[MAXN+10];      pii B[MAXM+10], C[MAXM+10];      int main()   {    scanf( %d , &N);    for(int i=1; i<=N; i++) scanf( %d , &A[i].first), A[i].second=i;    sort(A+1, A+N+1);       N=min(N, 10000);    for(int i=1; i<=N; i++)    {     for(int j=i-1; j>=1; j--)     {      int t=A[i].first-A[j].first;      if(B[t]==pii(0, 0))      {       B[t]={j, i};      }     }    }    for(int i=N; i>=1; i--)    {     for(int j=i+1; j<=N; j++)     {      int t=A[j].first-A[i].first;      if(C[t]==pii(0, 0))      {       C[t]={i, j};      }     }    }       for(int i=0; i<=MAXM; i++)    {     if(B[i]==pii(0, 0)) continue;     if(C[i]==pii(0, 0)) continue;     if(B[i].second<C[i].first)     {      printf( YES n );      printf( %d %d %d %d n , A[B[i].first].second, A[C[i].second].second, A[B[i].second].second, A[C[i].first].second);      return 0;     }    }    printf( NO n );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, s;     cin >> n;     n += 1;     int h[n];     for (int i = 1; i < n; i++) cin >> h[i];     h[0] = 0;     int energy = 0;     int max_energy = 0;     for (int i = 0; i < (n); ++i) {       if (i == 0) continue;       energy += h[i - 1] - h[i];       max_energy = min(max_energy, energy);     }     cout << -max_energy << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   T min(T a, T b, T c) {     return min(a, min(b, c));   }   template <class T>   T min(T a, T b, T c, T d) {     return min(a, min(b, min(c, d)));   }   template <class T>   T max(T a, T b, T c) {     return max(a, max(b, c));   }   template <class T>   T max(T a, T b, T c, T d) {     return max(a, max(b, max(c, d)));   }   bool cmp(int a, int b) { return a > b; }   long long GCD(long long a, long long b) { return (a % b) ? GCD(b, a % b) : b; }   const string namePro =  tmp ;   int main() {     int n;     scanf( %d , &n);     int cnt = 0;     int ans = 0;     stack<int> stk;     for (int i = (1); i <= (2 * n); ++i) {       string s;       cin >> s;       if (s ==  add ) {         int x;         scanf( %d , &x);         stk.push(x);       } else {         ++cnt;         if (stk.size() && stk.top() == cnt)           stk.pop();         else if (stk.empty())           continue;         else {           while (stk.size()) stk.pop();           ++ans;         }       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 41;   const int MASK = 1 << 21;   long long sz[MAX_N], par[MAX_N], po2[MAX_N], vis[MAX_N];   long long dp[MASK];   vector<int> adj[MAX_N];   int rt(int v) { return v ^ par[v] ? par[v] = rt(par[v]) : v; }   void join(int u, int v) {     if ((u = rt(u)) != (v = rt(v))) {       par[v] = u, sz[u] += sz[v];     }   }   int main() {     int n, m;     cin >> n >> m;     if (m < 3) {       cout << 0 << endl;       return 0;     }     po2[0] = 1;     for (int i = 0; i < n; i++) par[i] = i, sz[i] = 1;     for (int i = 1; i < n + 1; i++) po2[i] = po2[i - 1] * 2ll;     long long ans = po2[n];     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       a--, b--;       join(a, b);       adj[a].push_back(b);       adj[b].push_back(a);     }     set<long long> s;     long long num = 0;     for (int i = 0; i < n; i++) {       s.insert(rt(i));       if (sz[rt(i)] == 1) num++;     }     ans += po2[num + 1] - po2[s.size()];     bool imposs = false;     for (int i = 0; i < n; i++) {       if (vis[i]) continue;       queue<pair<int, int> > q;       q.push({i, 1});       while (q.size()) {         pair<int, int> curr = q.front();         q.pop();         if (vis[curr.first]) {           if (vis[curr.first] != curr.second) {             imposs = true;             break;           } else             continue;         }         vis[curr.first] = curr.second;         for (int next : adj[curr.first]) q.push({next, curr.second ^ 3});       }       if (imposs) break;     }     if (!imposs) ans += po2[s.size()];     num = 0;     for (int mask = 0; mask < 1 << ((n + 1) / 2); mask++) {       bool nowork = false;       long long new_mask = (1 << (n / 2)) - 1;       for (int k = 0; k < (n + 1) / 2; k++) {         if (!(mask & (1 << k))) continue;         for (int nxt : adj[2 * k]) {           if (nxt & 1)             new_mask &= (1 << (n / 2)) - (1 << (nxt / 2)) - 1;           else             nowork = nowork || (mask & (1 << (nxt / 2)));         }       }       if (!nowork) dp[new_mask]++;     }     for (int i = 0; i < n / 2; i++)       for (int mask = 0; mask < 1 << (n / 2); mask++)         if (mask != (mask | (1 << i))) dp[mask] += dp[mask | (1 << i)];     for (int mask = 0; mask < 1 << (n / 2); mask++) {       bool nowork = false;       for (int k = 0; k < n / 2; k++) {         if (!(mask & (1 << k))) continue;         for (long long nxt : adj[2 * k + 1]) {           if (nxt & 1 && mask & (1 << (nxt / 2))) nowork = true;         }       }       if (!nowork) num += dp[mask];     }     ans -= 2ll * num;     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   set<pair<long long int, long long int> > s;   pair<long long int, long long int> p;   long long int d[300000], x, n, k, l = 0, di = 0;   vector<long long int> v[300000];   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> x;       d[i] = x;       v[x].push_back(i);       di = max(x, di);     }     if (v[0].size() > 1 || v[1].size() > k) {       cout << -1;       return 0;     }     for (int i = 0; i <= di; i++)       if (v[i].size() == 0) {         cout << -1;         return 0;       }     for (int i = 0; i < v[1].size(); i++) s.insert({v[0][0], v[1][i]});     for (int i = 2; i <= di; i++) {       if (v[i - 1].size() * (k - 1) < v[i].size()) {         cout << -1;         return 0;       }       x = 1;       l = 0;       for (int j = 0; j < v[i].size(); j++) {         if (x > k - 1) {           l++;           x = 1;         }         s.insert({v[i - 1][l], v[i][j]});         x++;       }     }     cout << s.size() << endl;     while (!s.empty()) {       p = *s.begin();       cout << p.first <<     << p.second <<   n ;       s.erase(s.begin());     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, s, tot;   int a[5005], b[5005], c[5005], last[5005];   vector<int> edge[5005];   int cmp(int i, int j) { return c[i] > c[j]; }   long long dp[5005][5005];   int main() {     scanf( %d%d%d , &n, &m, &s);     int temp = s;     for (int i = 1; i <= n; i++) {       scanf( %d%d%d , &a[i], &b[i], &c[i]);       if (temp < a[i]) {         return printf( -1 n ), 0;       }       temp += b[i];       last[i] = i;     }     for (int i = 1; i <= m; i++) {       int x, y;       scanf( %d%d , &x, &y);       last[y] = max(last[y], x);     }     for (int i = 1; i <= n; i++) edge[last[i]].push_back(i);     for (int i = 1; i <= n; i++) {       sort(edge[i].begin(), edge[i].end(), cmp);     }     memset(dp, -1, sizeof(dp));     dp[0][s] = 0;     for (int i = 1; i <= n; i++) {       for (int j = 0; j <= 5000; j++)         if (j - b[i] >= a[i]) {           dp[i][j] = dp[i - 1][j - b[i]];         }       int len = edge[i].size();       for (int j = 1; j <= 5000; j++)         if (dp[i][j] != -1) {           long long res = 0;           for (int k = 0; k < len; k++)             if (j - k - 1 >= 0) {               res += c[edge[i][k]];               dp[i][j - k - 1] = max(dp[i][j] + res, dp[i][j - k - 1]);             }         }     }     long long ans = 0;     for (int i = 0; i <= 5000; i++) {       ans = max(ans, dp[n][i]);     }     printf( %lld n , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const double eps = 1e-9;   double mi[N], ma[N];   double pre1[N], pre2[N];   double ans1[N], ans2[N];   int main() {     int n;     scanf( %d , &n);     for (int i = (1); i <= (n); i++) cin >> ma[i];     for (int i = (1); i <= (n); i++) cin >> mi[i];     for (int i = (1); i <= (n); i++) pre1[i] = pre1[i - 1] + ma[i];     for (int i = n; i >= 1; i--) pre2[i] = pre2[i + 1] + mi[i];     for (int i = (1); i <= (n); i++) {       double t1 = pre2[i + 1] - pre1[i] - 1.0;       double t3 = t1 * t1 - 4.0 * pre1[i];       if (t3 < eps) t3 = 0.0;       t3 = sqrt(t3);       ans1[i] = 0.5 * (-t1 + t3);       ans2[i] = 0.5 * (-t1 - t3);     }     for (int i = (1); i <= (n); i++) printf( %.9lf  , ans1[i] - ans1[i - 1]);     puts(  );     for (int i = (1); i <= (n); i++) printf( %.9lf  , ans2[i] - ans2[i - 1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   void solve() {     long long n;     cin >> n;     if (n < 6)       cout <<  -1  << endl;     else {       cout <<  1 2 n2 3 n2 4 n1 5 n1 6 n ;       for (long long i = 7; i <= n; i++) {         cout << 2 <<     << i << endl;       }     }     cout <<  1 2 n ;     for (long long i = 3; i <= n; i++) {       cout << 2 <<     << i << endl;     }   }   signed main() {     long long t = 1;     ios_base::sync_with_stdio(false);     cin.tie(NULL);     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   long long pot[35];   int numbits(long long n) {     int conta = 0;     for (int i = 0; i <= 33; i++) {       if (n & pot[i]) conta++;     }     return conta;   }   int main() {     pot[0] = 1;     for (int i = 1; i <= 33; i++) pot[i] = 2 * pot[i - 1];     long long n, p;     scanf( %lld %lld , &n, &p);     if (p == 0)       printf( %d n , numbits(n));     else if (p < 0) {       int k = 0;       bool teste = true;       while (teste) {         if (numbits(n - k * p) <= k) {           printf( %d n , k);           teste = false;         } else           k++;       }     } else {       int k = 0;       bool funfa = false;       while (k <= (n / (p + 1)) && funfa == false) {         if (numbits(n - k * p) <= k) {           printf( %d n , k);           funfa = true;         }         k++;       }       if (!funfa) printf( -1 n );     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int a[6];     for (int i = 0; i < 6; i++) {       a[i] = s[i] - 48;     }     int sum1 = a[0] + a[1] + a[2];     int sum2 = a[3] + a[4] + a[5];     int difference = abs(sum1 - sum2);     int flag = 0;     if (sum1 > sum2) flag = 3;     for (int i = flag; i <= flag + 2; i++) {       a[i] = 9 - a[i];     }     int count = 0;     int sum = 0;     if (difference == 0) {       cout << 0 << endl;       return 0;     }     while (1) {       int maxi = 0;       for (int i = 0; i < 6; i++) {         if (a[maxi] < a[i]) maxi = i;       }       if (a[maxi] == -1) return 0;       count += 1;       sum += a[maxi];       if (sum >= difference) {         cout << count << endl;         return 0;       }       a[maxi] = -1;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int low = 0, up = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] < 93) {         up++;       } else {         low++;       }     }     if (low >= up) {       for (int i = 0; i < s.size(); i++) {         s[i] = tolower(s[i]);       }     } else {       for (int i = 0; i < s.size(); i++) {         s[i] = toupper(s[i]);       }     }     cout << s;   }