malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < int(n); i++) cin >> a[i];     long long diff = 0;     int m = a[0];     int ans = 0;     for (int i = 0; i < n; i++) {       if (a[i] >= m) {         m = a[i];       } else {         diff = (m - a[i]);         int d = floor(log2(diff)) + 1;         ans = max(d, ans);       }     }     cout << ans << endl;   }   int main() {     cin.tie(0);     ios_base::sync_with_stdio(false);     int t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long fa[400005], iv[400005];   pair<long long, long long> p[2005];   long long dp[2005];   long long pw(long long bs, long long x) {     long long ans = 1;     while (x) {       if (x & 1) ans = ans * bs % 1000000007;       bs = bs * bs % 1000000007;       x /= 2;     }     return ans % 1000000007;   }   void init() {     fa[0] = iv[0] = 1;     for (int i = 1; i <= 400000; i++) {       fa[i] = fa[i - 1] * i % 1000000007;       iv[i] = pw(fa[i], 1000000007 - 2) % 1000000007;     }   }   long long cal(long long n, long long m) {     if (m > n) return 0;     long long ans = fa[n] % 1000000007;     ans = (ans * iv[m] % 1000000007) * iv[n - m] % 1000000007;     return ans;   }   long long lu(long long n, long long m) {     if (m == 0) return 1;     return cal(n % 1000000007, m % 1000000007) *            lu(n / 1000000007, m / 1000000007) % 1000000007;   }   int main() {     init();     long long n, m, k;     cin >> n >> m >> k;     n--;     m--;     for (int i = 0; i < k; i++) {       cin >> p[i].first >> p[i].second;       p[i].first--;       p[i].second--;     }     sort(p, p + k);     p[k].first = n;     p[k].second = m;     for (int i = 0; i <= k; i++) {       long long sum = 0;       for (int j = 0; j < i; j++) {         long long x = p[i].first - p[j].first, y = p[i].second - p[j].second;         if (x < 0 || y < 0) continue;         sum = (sum + lu(x + y, x) * dp[j] % 1000000007) % 1000000007;       }       dp[i] = (cal(p[i].first + p[i].second, p[i].first) - sum + 1000000007) %               1000000007;     }     cout << dp[k] % 1000000007 << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXPOW = 20;   const int MAXA = 1048577;   const int MAXN = 100009;   int n;   int k;   vector<int> a;   unordered_set<int> visited[MAXN];   bool used[MAXA];   void gen() {     freopen( input.txt ,  w , stdout);     n = 100000;     printf( %d n , n);     for (int i = 0; i < n; ++i) printf( %d  , rand() % 1000001);     exit(0);   }   int stupid() {     used[0] = true;     for (int i = 0; i < n; ++i) {       int x = 0;       for (int j = i; j < n; ++j) {         x |= a[j];         if (!used[x]) {           cerr <<  i                 <<  :   << i << endl;           ;           cerr <<  j                 <<  :   << j << endl;           ;           cerr <<  x                 <<  :   << x << endl;           ;         }         used[x] = true;       }     }     int cnt = 0;     for (int i = 0; i < MAXA; ++i)       if (used[i]) cnt++;     return cnt;   }   int main() {     scanf( %d , &n);     a.resize(n);     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);     }     for (int i = 0; i < n; ++i) {       int x = 0;       for (int j = i; j < n; ++j) {         x |= a[j];         if (visited[j].find(x) != visited[j].end()) break;         visited[j].insert(x);         used[x] = true;       }     }     int cnt = 0;     for (int i = 0; i < MAXA; ++i)       if (used[i]) cnt++;     printf( %d n , cnt);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int Mo[N], a[N];   inline int gi() {     int x = 0, o = 1;     char ch = getchar();     while (ch !=  -  && (ch <  0  || ch >  9 )) ch = getchar();     if (ch ==  - ) ch = getchar(), o = -1;     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x * o;   }   inline int phi(int x) {     int ret = x, y = x;     for (int i = 2; i * i <= y; i++)       if (x % i == 0) {         while (x % i == 0) x /= i;         ret = ret / i * (i - 1);       }     if (x > 1) ret = ret / x * (x - 1);     return ret;   }   inline void calc(int &x, int y, int M) {     long long c = 1LL * x * y;     x = (c < M ? c : c % M + M);   }   inline int Pow(int x, int y, int M) {     int ret = 1;     while (y) {       if (y & 1) calc(ret, x, M);       calc(x, x, M), y >>= 1;     }     return ret;   }   inline int solve(int l, int r, int t) {     if (Mo[t] == 1) return 1;     if (l == r) {       if (a[l] < Mo[t]) return a[l];       return a[l] % Mo[t] + Mo[t];     }     return Pow(a[l], solve(l + 1, r, t + 1), Mo[t]);   }   int main() {     int n, m, q;     cin >> n >> m;     Mo[1] = m;     for (int i = 1; Mo[i] ^ 1;) Mo[++i] = m = phi(m);     for (int i = 1; i <= n; i++) a[i] = gi();     cin >> q;     while (q--) {       int l = gi(), r = gi();       printf( %d n , solve(l, r, 1) % Mo[1]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       string s;       cin >> s;       long long i;       map<char, long long> mp;       for (i = 0; i < n; i++) {         mp[s[i]]++;       }       if (n == 2) {         if (s[0] >= s[1]) {           cout <<  NO  << endl;         } else {           cout <<  YES  << endl;           cout << 2 << endl;           cout << s[0] <<     << s.substr(1, n) << endl;         }       } else {         cout <<  YES  << endl;         cout << 2 << endl;         cout << s[0] <<     << s.substr(1, n) << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, y, flag = 0;     cin >> n >> x >> y;     n /= 2;     if ((n == x && n == y) || (n == (x - 1) && n == (y - 1)) ||         (n == (x) && n == (y - 1)) || (n == (x - 1) && n == (y)))       flag = 1;     if (flag)       cout <<  NO  << endl;     else       cout <<  YES  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200005;   const int inf = 1000000007;   int main() {     int a, b, c;     int x, y, z;     cin >> a >> b >> c;     cin >> x >> y >> z;     int da = a - x;     int db = b - y;     int dc = c - z;     int can = max(0, da / 2) + max(0, db / 2) + max(0, dc / 2);     int needed = min(0, da) + min(0, db) + min(0, dc);     cout << (can + needed >= 0 ?  Yes  :  No ) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   long long s[211111], mx[211111];   int a[211111], bg[211111];   long long hf, ans;   int bhf, aa, bb;   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       s[i] = s[i - 1] + a[i];     }     for (int i = k; i <= n; ++i) {       if (s[i] - s[i - k] > mx[i - 1]) {         mx[i] = s[i] - s[i - k];         bg[i] = i - k + 1;       } else         mx[i] = mx[i - 1], bg[i] = bg[i - 1];     }     hf = 0;     for (int i = n - k + 1; i >= 1; --i) {       if (mx[i] + hf >= ans) {         long long tmp = ans;         ans = mx[i] + hf;         if (tmp < ans) aa = bg[i], bb = bhf;         if (bg[i] < aa || (bg[i] == aa && bhf < bb)) {           aa = bg[i], bb = bhf;         }       }       if (s[i + k - 1] - s[i - 1] >= hf) {         hf = s[i + k - 1] - s[i - 1];         bhf = i;       }     }     cout << aa <<     << bb << endl;   }
#include <bits/stdc++.h>   using namespace std;   string s[100] = {        111111101010101111100101001111111 ,  100000100000000001010110001000001 ,        101110100110110000011010001011101 ,  101110101011001001111101001011101 ,        101110101100011000111100101011101 ,  100000101010101011010000101000001 ,        111111101010101010101010101111111 ,  000000001111101111100111100000000 ,        100010111100100001011110111111001 ,  110111001111111100100001000101100 ,        011100111010000101000111010001010 ,  011110000110001111110101100000011 ,        111111111111111000111001001011000 ,  111000010111010011010011010100100 ,        101010100010110010110101010000010 ,  101100000101010001111101000000000 ,        000010100011001101000111101011010 ,  101001001111101111000101010001110 ,        101101111111000100100001110001000 ,  000010011000100110000011010000010 ,        001101101001101110010010011011000 ,  011101011010001000111101010100110 ,        111010100110011101001101000001110 ,  110001010010101111000101111111000 ,        001000111011100001010110111110000 ,  000000001110010110100010100010110 ,        111111101000101111000110101011010 ,  100000100111010101111100100011011 ,        101110101001010000101000111111000 ,  101110100011010010010111111011010 ,        101110100100011011110110101110000 ,  100000100110011001111100111100000 ,        111111101101000101001101110010001 };   int main() {     int x, y;     scanf( %d%d , &x, &y);     printf( %c , s[x][y]);   }
#include <bits/stdc++.h>   using namespace std;   long long n, a[1000003];   pair<long long, long long> b[1000003];   long long calc1() {     for (int i = 0; i < n; i++) b[i] = make_pair(-a[i], i);     sort(b, b + n);     set<signed> s1;     s1.insert(-1);     s1.insert(n);     long long ret = 0;     for (int i = 0; i < n; i++) {       set<int>::iterator tmpr = s1.lower_bound(b[i].second), tmpl = prev(tmpr);       ret -= (b[i].second - *tmpl) * (*tmpr - b[i].second) * b[i].first;       s1.insert(b[i].second);     }     return ret;   }   long long calc2() {     for (int i = 0; i < n; i++) b[i] = make_pair(-b[i].first, b[i].second);     for (int i = 0; i < n / 2; i++) swap(b[i], b[n - i - 1]);     set<signed> s1;     s1.insert(-1);     s1.insert(n);     long long ret = 0;     for (int i = 0; i < n; i++) {       set<int>::iterator tmpr = s1.lower_bound(b[i].second), tmpl = prev(tmpr);       ret += (b[i].second - *tmpl) * (*tmpr - b[i].second) * b[i].first;       s1.insert(b[i].second);     }     return ret;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) scanf( %lld , a + i);     cout << calc1() - calc2();   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int i, j, k, n, m;   pair<int, int> p[N];   int a[N];   int c[N];   int main() {     cin >> n;     for (i = 0; i < n; ++i) {       cin >> p[i].first;       p[i].second = i;     }     sort(p, p + n);     k = 0;     for (i = 0; i < n; ++i) {       c[p[i].first]++;       k = max(k, p[i].first);     }     for (i = 1; i <= k; ++i)       if (c[i] == 0 || (i > 1 && c[i] > c[i - 1])) {         cout << -1 << endl;         return 0;       }     m = 0;     k = 0;     for (i = 0; i < n; ++i) {       if (!i || p[i].first != p[i - 1].first) {         k = 0;       }       ++k;       m = max(m, k);       a[p[i].second] = k;     }     cout << m << endl;     for (i = 0; i < n; ++i) {       cout << a[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct _ {     ios_base::Init i;     _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); }   } _;   const int lgn = 32;   int n;   vector<vector<int>> gr;   vector<vector<int>> P;   vector<int> lvl, ans, dp;   map<pair<int, int>, int> ind;   void pre(int curr, int par) {     lvl[curr] = lvl[par] + 1;     P[curr][0] = par;     for (int j = 1; j <= lgn; j++) P[curr][j] = P[P[curr][j - 1]][j - 1];     for (auto child : gr[curr]) {       if (child == par) continue;       pre(child, curr);     }     return;   }   int lca(int u, int v) {     if (lvl[u] > lvl[v]) swap(u, v);     for (int j = lgn; j >= 0; j--) {       if (lvl[P[v][j]] >= lvl[u]) v = P[v][j];     }     if (u == v) return u;     for (int j = lgn; j >= 0; j--) {       if (P[u][j] != P[v][j]) u = P[u][j], v = P[v][j];     }     return P[u][0];   }   void pull(int curr, int par) {     for (auto child : gr[curr]) {       if (child == par) continue;       pull(child, curr);       dp[curr] += dp[child];     }     if (curr != 1) ans[ind[{curr, par}]] = dp[curr];     return;   }   int main() {     cin >> n;     gr.resize(n + 1);     lvl.resize(n + 1, 0);     dp.resize(n + 1, 0);     ans.resize(n - 1, 0);     P.resize(n + 1, vector<int>(lgn + 1, 0));     for (int i = 0; i <= n - 2; i++) {       int u, v;       cin >> u >> v;       gr[u].push_back(v);       gr[v].push_back(u);       ind[{u, v}] = ind[{v, u}] = i;     }     pre(1, 1);     int q;     cin >> q;     while (q--) {       int a, b;       cin >> a >> b;       if (lvl[a] > lvl[b]) swap(a, b);       int lc = lca(a, b);       if (lc == a) {         dp[b]++;         dp[a]--;       } else {         dp[a]++;         dp[b]++;         dp[lc] -= 2;       }     }     pull(1, 1);     for (int i = 0; i <= n - 2; i++) cout << ans[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool rsort1(const pair<long long int, long long int> &a,               const pair<long long int, long long int> &b) {     return (a.first > b.first);   }   bool rsort2(const pair<long long int, long long int> &a,               const pair<long long int, long long int> &b) {     return (a.second > b.second);   }   bool sort2(const pair<long long int, long long int> &a,              const pair<long long int, long long int> &b) {     return (a.second < b.second);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int h, m;       cin >> h >> m;       if (m == 0)         cout << (24 - h) * 60 <<   n ;       else         cout << (23 - h) * 60 + (60 - m) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n == 1) {       cout << 1;       return 0;     }     long long a[100005];     for (int i = 0; i < n; i++) cin >> a[i];     long long ans = 0, kol = 1;     for (int i = 0; i < n - 1; i++)       if (a[i] == a[i + 1])         kol++;       else {         ans += kol * (kol + 1) / 2;         kol = 1;       }     ans += kol * (kol + 1) / 2;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, p, q, a;     cin >> p >> q >> n;     for (int i = 1; i <= n; i++) {       cin >> a;       if (q == 0 || a > p / q) return cout <<  NO , 0;       p -= q * a;       swap(p, q);     }     cout << ((q) ?  NO  :  YES );   }
#include <bits/stdc++.h>   #define maxn 1086      using namespace std;      typedef long long ll;      int n, m;   ll a[maxn][maxn];   ll sum[maxn], sum2[maxn];   map<ll, int> mp;      int main(){    scanf( %d%d , &m, &n);    for(int i = 1;i <= n;i++) for(int j = 1;j <= m;j++) scanf( %lld , &a[i][j]);    for(int i = 1;i <= n;i++) for(int j = 1;j <= m;j++) sum[i] += a[i][j], sum2[i] += a[i][j] * a[i][j];    for(int i = 2;i <= n;i++) mp[sum[i] - sum[i - 1]]++;    int mx = 0;    ll d, val;    for(map<ll, int>::iterator it = mp.begin();it != mp.end();++it){     if(it->second > mx) mx = it->second, d = it->first;    }    int x;    for(int i = 2;i <= n;i++){     if(sum[i] - sum[i - 1] != d){      if(i == n) x = n, val = d - (sum[i] - sum[i - 1]);      else if(sum[i + 1] - sum[i] != d) x = i, val = d - (sum[i] - sum[i - 1]);      else x = 1, val = sum[i] - sum[i - 1] - d;      break;     }    }    ll d2;    if(x > 3) d2 = (sum2[1] + sum2[3] - 2 * sum2[2]) / 2;    else d2 = (sum2[n - 2] + sum2[n] - 2 * sum2[n - 1]) / 2;    for(int i = 1;i <= m;i++){     if(x == 1){      if(sum2[x] - a[x][i] * a[x][i] + (a[x][i] + val) * (a[x][i] + val) + sum2[x + 2] - 2 * sum2[x + 1] == 2 * d2) return printf( %d %d , x - 1, a[x][i] + val), 0;     }else if(x == n){      if(sum2[x - 2]+ sum2[x] - a[x][i] * a[x][i] + (a[x][i] + val) * (a[x][i] + val) - 2 * sum2[x - 1] == 2 * d2) return printf( %d %d , x - 1, a[x][i] + val), 0;     }else{      if(sum2[x - 1] + sum2[x + 1] - 2 * (sum2[x] - a[x][i] * a[x][i] + (a[x][i] + val) * (a[x][i] + val)) == 2 * d2) return printf( %d %d , x - 1, a[x][i] + val), 0;     }    }       }
#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<int> A, B;   int d[10000010];   int a[10000010];   int pr[10010], pn;   bool isp[100010];   void GetPrime(int n) {     memset(isp + 2, 1, sizeof(isp) - 2);     for (int i = 2; i < n; i++) {       if (isp[i]) pr[pn++] = i;       for (int j = 0; j < pn && pr[j] * i < n; j++) {         isp[pr[j] * i] = 0;         if (i % pr[j] == 0) break;       }     }   }   int main() {     std::ios::sync_with_stdio(false);     GetPrime(10000);     cin >> n >> m;     A.resize(n), B.resize(m);     for (int i = 0; i < n; i++) cin >> A[i];     for (int i = 0; i < m; i++) cin >> B[i];     for (int i = 0; i < n; i++) {       int t = A[i];       for (int j = 0; pr[j] * pr[j] <= t; j++) {         while (t % pr[j] == 0) d[pr[j]]++, t /= pr[j];       }       if (t > 1) d[t]++;     }     for (int i = 0; i < m; i++) {       int t = B[i];       for (int j = 0; pr[j] * pr[j] <= t; j++) {         while (t % pr[j] == 0) d[pr[j]]--, t /= pr[j];       }       if (t > 1) d[t]--;     }     cout << n <<     << m << endl;     for (int i = 0; i < n; i++) {       int r = 1;       int t = A[i];       for (int j = 0; pr[j] * pr[j] <= t; j++) {         while (t % pr[j] == 0) {           t /= pr[j];           if (d[pr[j]] > 0) {             d[pr[j]]--;             r *= pr[j];           }         }       }       if (t > 1 && d[t] > 0) d[t]--, r *= t;       cout << r <<    ;     }     cout << endl;     for (int i = 0; i < m; i++) {       int r = 1;       int t = B[i];       for (int j = 0; pr[j] * pr[j] <= t; j++) {         while (t % pr[j] == 0) {           t /= pr[j];           if (d[pr[j]] < 0) {             d[pr[j]]++;             r *= pr[j];           }         }       }       if (t > 1 && d[t] < 0) d[t]++, r *= t;       cout << r <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     long long x, y;     long long a = 0, d = 0;     for (long long i = 0; i < n; i++) {       cin >> x >> y;       if (x < 0) {         a++;       } else         d++;     }     if (a <= 1) {       cout <<  Yes  << endl;     } else if (d <= 1) {       cout <<  Yes  << endl;     } else {       cout <<  No  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, k, ans, mx;   vector<vector<int>> g;   vector<bool> vis;   bool a[100001];   void bfs(int src) {     vis[src] = true;     queue<int> q;     q.push(src);     while (!q.empty()) {       int u = q.front();       q.pop();       for (int i = 0; i < g[u].size(); i++) {         int v = g[u][i];         if (!vis[v]) {           vis[v] = true;           q.push(v);           ans++;         }       }     }   }   int main() {     scanf( %d%d , &n, &k);     g.resize(n);     vis.resize(n);     for (int a, b, i = 0; i < k; i++) {       scanf( %d%d , &a, &b);       --a;       --b;       g[a].push_back(b);       g[b].push_back(a);     }     for (int i = 0; i < n; i++) {       if (!vis[i]) bfs(i);     }     cout << k - ans;   }
#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   long long N = 100107;   long long binpow(long long x, long long y) {     if (y == 0) return 1;     if (y == 1)       return x % mod;     else if (y % 2 == 0) {       long long w = binpow(x, y / 2) % mod;       return (w * w) % mod;     } else       return ((x % mod) * (binpow(x, y - 1) % mod)) % mod;   }   int main() {     long long t = 1;     cin >> t;     while (t--) {       long long n, m, k, kol = 0, sum = 0;       set<long long> se1;       set<long long> se2;       vector<long long> v;       string s;       cin >> n >> m;       long long a[n + 10][m + 10];       for (long long i = 1; i <= n; i++)         for (long long j = 1; j <= m; j++) {           cin >> a[i][j];           if (a[i][j] == 1) {             se1.insert(i);             se2.insert(j);           }         }       long long mn = min(n - se1.size(), m - se2.size());       if (mn % 2 == 0)         cout <<  Vivek ;       else         cout <<  Ashish ;       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a, b, fr, k1, k2;   int dist[3005][3005];   bool flag[3005][3005];   vector<int> v[3005];   queue<int> q;   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d %d , &a, &b);       v[a].push_back(b);       v[b].push_back(a);     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) dist[i][j] = 1e9;     memset(flag, 1, sizeof(flag));     for (int k = 1; k <= n; k++) {       while (!q.empty()) q.pop();       q.push(k);       dist[k][k] = 0;       while (!q.empty()) {         fr = q.front();         q.pop();         flag[fr][fr] = false;         for (int i = 0; i < v[fr].size(); i++) {           if (flag[k][v[fr][i]]) {             flag[k][v[fr][i]] = false;             dist[k][v[fr][i]] = dist[k][fr] + 1;             q.push(v[fr][i]);           }         }       }     }     int s1, t1, l1, s2, t2, l2, ans = -1;     scanf( %d %d %d , &s1, &t1, &l1);     scanf( %d %d %d , &s2, &t2, &l2);     for (int i = 1; i < n; i++) {       for (int j = i + 1; j <= n; j++) {         k1 = min(dist[s1][i] + dist[i][j] + dist[j][t1],                  dist[s1][j] + dist[i][j] + dist[i][t1]);         k2 = min(dist[s2][i] + dist[i][j] + dist[j][t2],                  dist[s2][j] + dist[i][j] + dist[i][t2]);         if (k1 <= l1 && k2 <= l2) {           ans = max(ans, m - k1 - k2 + dist[i][j]);         }       }     }     if (dist[s1][t1] <= l1 && dist[s2][t2] <= l2) {       ans = max(ans, m - dist[s1][t1] - dist[s2][t2]);     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int cnt[200001], n, par;   vector<int> adj[200001];   vector<pair<int, int> > v;   void count(int h, int p) {     cnt[h]++;     for (auto it : adj[h])       if (it ^ p) {         count(it, h);         cnt[h] += cnt[it];       }   }   int ct(int h, int p) {     for (auto it : adj[h])       if (it ^ p) {         if (cnt[it] > n / 2) return ct(it, h);       }     par = p;     return h;   }   vector<pair<int, pair<int, int> > > res;   void dfs(int h, int p) {     for (auto it : adj[h])       if (it ^ p) {         dfs(it, h);       }     v.push_back({h, p});   }   void f(int h, int p) {     v.clear();     dfs(h, p);     v.pop_back();     int t = h;     for (auto it : v) {       res.push_back({p, {t, it.first}});       res.push_back({it.first, {it.second, h}});       t = it.first;     }     res.push_back({p, {t, h}});   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       adj[x].push_back(y);       adj[y].push_back(x);     }     count(1, 0);     int cen = ct(1, 0), cen2 = 0;     for (auto it : adj[cen])       if (par ^ it && 2 * cnt[it] == n) cen2 = it;     for (auto it : adj[cen])       if (it ^ cen2) f(it, cen);     for (auto it : adj[cen2])       if (it ^ cen) f(it, cen2);     printf( %d n , res.size());     for (auto it : res)       printf( %d %d %d n , it.first, it.second.first, it.second.second);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     ;     long long t;     cin >> t;     while (t--) {       long long n, m;       cin >> n >> m;       string s;       cin >> s;       vector<long long> p(m), arr(26, 0);       vector<long long> ans(n, 0);       for (int i = 0; i < int(m); i++) {         cin >> p[i];         ++ans[p[i] - 1];       }       for (long long i = n - 1; i > 0; --i) ans[i - 1] += ans[i];       for (int i = 0; i < int(n); i++) {         arr[s[i] -  a ] += ans[i] + 1;       }       for (int i = 0; i < int(26); i++) cout << arr[i] <<    ;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, bal;   string s, t;   int main() {     ios_base::sync_with_stdio(false);     cin >> s;     n = s.length();     bal = m = 0;     for (int i = n - 1; i >= 0; --i) {       if (s[i] ==  0 )         --bal;       else {         if (bal + m >= 0) {           int j = i;           while (j >= 0 && s[j] ==  1 ) {             s[j] =  0 ;             --j;             ++m;           }           --bal;         } else           ++bal;       }     }     cout << s;     return 0;   }