malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   vector<int> cities[100000], T[100000];   bool visited[100000];   int tin[100000], low[100000], tv[100000];   int up[100000][20];   map<pair<int, int>, int> b;   int c = 0, n, l, m, k;   void dfs1(int v, int p = -1) {     visited[v] = true;     tin[v] = low[v] = c++;     for (int dest : cities[v]) {       if (dest == p) continue;       if (visited[dest]) {         low[v] = min(low[v], tin[dest]);       } else {         dfs1(dest, v);         low[v] = min(low[v], low[dest]);         if (low[dest] > tin[v]) {           b[{min(v, dest), max(dest, v)}] = 1;         }       }     }   }   void preprocessbridges() {     memset(visited, false, sizeof visited);     memset(tin, -1, sizeof tin);     memset(low, -1, sizeof low);     for (int i = 0; i < n; ++i) {       if (!visited[i]) {         dfs1(i);       }     }   }   void Tdfs(int u, int d) {     visited[u] = true;     tv[u] = d;     for (int v : cities[u]) {       if (visited[v]) continue;       T[u].push_back(v);       T[v].push_back(u);       Tdfs(v, d + b[{min(u, v), max(u, v)}]);     }   }   void dfs(int v, int p) {     tin[v] = c++;     up[v][0] = p;     for (int i = 1; i <= l; ++i) {       up[v][i] = up[up[v][i - 1]][i - 1];     }     for (int u : T[v]) {       if (u == p) {         continue;       }       dfs(u, v);     }     low[v] = c++;   }   bool is_ancestor(int u, int v) { return tin[u] <= tin[v] && low[u] >= low[v]; }   int lca(int u, int v) {     if (is_ancestor(u, v)) {       return u;     }     if (is_ancestor(v, u)) {       return v;     }     for (int i = l; i >= 0; --i) {       if (!is_ancestor(up[u][i], v)) {         u = up[u][i];       }     }     return up[u][0];   }   void preprocesslca() {     memset(visited, false, sizeof visited);     memset(tv, 0, sizeof tv);     Tdfs(0, -1);     memset(tin, 0, sizeof tin);     memset(low, 0, sizeof low);     c = 0;     l = ceil(log2(n));     memset(up, 0, sizeof up);     dfs(0, 0);   }   void preprocess() {     preprocessbridges();     preprocesslca();   }   int solve(int r, int e) { return tv[r] + tv[e] - 2 * tv[lca(r, e)]; }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       cities[x - 1].push_back(y - 1);       cities[y - 1].push_back(x - 1);     }     preprocess();     cin >> k;     while (k--) {       int root, shop;       cin >> root >> shop;       cout << solve(root - 1, shop - 1) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long sum[500001], ans;   long long solve(long long a, long long b, long long c, long long hh) {     if (a < b + c) return 0ll;     long long now = min(a - b - c, hh);     return (now + 1) * (now + 2) / 2;   }   int main() {     long long a, b, c, l, i;     scanf( %lld%lld%lld%lld , &a, &b, &c, &l);     sum[0] = 1;     for (i = 1; i <= l; i++) sum[i] = sum[i - 1] + (i + 1) * (i + 2) / 2;     ans = sum[l];     for (i = 0; i <= l; i++)       ans -= solve(a + i, b, c, l - i) + solve(b + i, a, c, l - i) +              solve(c + i, a, b, l - i);     printf( %lld , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 10005;   long long n, m, a[maxn], b[maxn];   int k;   long long gcd(long long a, long long b) {     if (!b) return a;     return gcd(b, a % b);   }   long long exgcd(long long a, long long b, long long &x, long long &y) {     if (!b) {       x = 1, y = 0;       return a;     }     long long r = exgcd(b, a % b, x, y), x0 = x;     x = y;     y = x0 - (a / b) * y;     return r;   }   long long CRT(long long *m, long long *a) {     long long lcm = 1, X = m[1], Y = a[1];     for (int i = 1; i <= k; i++) lcm = lcm / gcd(lcm, m[i]) * m[i];     for (int i = 2; i <= k; i++) {       long long A = X, B = m[i], d, x, y, c = a[i] - Y;       d = exgcd(A, B, x, y);       if (c % d) return -1;       long long mod = m[i] / d;       long long K = ((x * c / d) % mod + mod) % mod;       Y = X * K + Y;       X = X * m[i] / d;     }     if (Y == 0) return lcm;     return Y;   }   bool check() {     long long I = CRT(a, b), J;     if (I > n || I <= 0) return 0;     for (int i = 1; i <= k; i++) b[i] = 1 - i;     J = CRT(a, b);     if (J + k - 1 > m || J <= 0) return 0;     for (int i = 1; i <= k; i++)       if (gcd(I, J + i - 1) != a[i]) return 0;     return 1;   }   int main() {     cin >> n >> m >> k;     for (int i = 1; i <= k; i++) cin >> a[i];     if (check())       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100 * 1000 + 17;   long long n, a[MAXN], ans;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i < n; i++) {       int t = log2(n - i);       a[i + (1 << t)] += a[i];       ans += a[i];       a[i] = 0;       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[101];   void scan() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     sort(a, a + n);   }   void out() {     int ans = 0, k = 0, c;     while (1) {       c = 0;       for (int i = 0; i < n; i++) {         if (a[i] != -1) {           if (a[i] >= k) {             ++k;             a[i] = -1;           }         } else if (a[i] == -1)           ++c;       }       if (c == n) break;       ++ans;       k = 0;     }     cout << ans <<   n ;   }   int main() {     scan();     out();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n;   vector<pair<long long, long long> > serv;   bool check(long long x1, long long x2) {     long long pos = 0;     bool found = false;     for (long long i = n - 1; i >= 0; --i) {       if (serv[i].first * (n - i) >= x2) {         found = true;         pos = i;         break;       }     }     if (!found) {       return false;     }     found = false;     for (long long i = pos - 1; i >= 0; --i) {       if (serv[i].first * (pos - i) >= x1) {         found = true;         break;       }     }     return found;   }   pair<vector<long long>, vector<long long> > print(long long x1, long long x2) {     vector<long long> a1, a2;     long long pos = 0;     for (long long i = n - 1; i >= 0; --i) {       a2.push_back(serv[i].second);       if (serv[i].first * (n - i) >= x2) {         pos = i;         break;       }     }     for (long long i = pos - 1; i >= 0; --i) {       a1.push_back(serv[i].second);       if (serv[i].first * (pos - i) >= x1) {         break;       }     }     return {a1, a2};   }   void solve() {     long long x1 = 0, x2 = 0;     cin >> n >> x1 >> x2;     serv.resize(n);     for (long long i = 0; i < n; ++i) {       cin >> serv[i].first;       serv[i].second = i;     }     sort(serv.begin(), serv.end());     if (check(x1, x2)) {       cout <<  Yes  << endl;       auto ans = print(x1, x2);       cout << ans.first.size() <<     << ans.second.size() << endl;       for (long long x : ans.first) cout << x + 1 <<    ;       cout << endl;       for (long long x : ans.second) cout << x + 1 <<    ;       cout << endl;     } else if (check(x2, x1)) {       cout <<  Yes  << endl;       auto ans = print(x2, x1);       cout << ans.second.size() <<     << ans.first.size() << endl;       for (long long x : ans.second) cout << x + 1 <<    ;       cout << endl;       for (long long x : ans.first) cout << x + 1 <<    ;       cout << endl;     } else {       cout <<  No  << endl;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 9, base = 27;   int cnt_list, pos[20200], pa[20100], len[20100], fs[20100], pc[20100],       ls[20100], cnt_ls, tmp[20100], cnt, n, num_q;   struct pp {     int id;     char ch;   };   vector<pp> adj[20201];   pp now;   void dfs(int id, int pr) {     int i, j, s, p, q, ip;     pos[id] = cnt_list++;     pa[pos[id]] = pr;     for (i = 0; i < adj[id].size(); i++) {       ip = adj[id][i].id;       if (pos[ip] >= 0) continue;       pc[cnt_list] = adj[id][i].ch -  a ;       dfs(ip, pos[id]);     }   }   int main() {     int id1, id2, i, j, s, p, q, x, y, fg;     char ch;     scanf( %d%d , &n, &num_q);     for (i = 0; i < n - 1; i++) {       scanf( %d%d , &id1, &id2);       ch = getchar();       while (ch <  a  || ch >  z ) ch = getchar();       id1--;       id2--;       now.id = id2;       now.ch = ch;       adj[id1].push_back(now);       now.id = id1;       now.ch = ch;       adj[id2].push_back(now);     }     memset(pos, -1, sizeof(pos));     dfs(0, -1);     while (num_q--) {       scanf( %d%d , &x, &y);       x--;       y--;       x = pos[x];       y = pos[y];       int u, v;       u = x;       v = y;       cnt_ls = cnt = 0;       while (u != v) {         if (u > v) {           ls[cnt_ls++] = pc[u];           u = pa[u];         } else {           tmp[cnt++] = pc[v];           v = pa[v];         }       }       while (cnt > 0) ls[cnt_ls++] = tmp[--cnt];       for (i = 0; i < n; i++) len[i] = -1;       u = x;       fs[u] = len[u] = 0;       int ans = 0;       while (u != 0) {         len[pa[u]] = len[u] + 1;         if (fs[u] == 0) {           if (len[u] < cnt_ls) {             if (ls[len[u]] > pc[u])               fs[pa[u]] = -1;             else if (ls[len[u]] < pc[u])               fs[pa[u]] = 1;             else               fs[pa[u]] = 0;           } else             fs[pa[u]] = 1;         } else           fs[pa[u]] = fs[u];         if (fs[pa[u]] < 0 || (fs[pa[u]] == 0 && len[pa[u]] != cnt_ls)) ans++;         u = pa[u];       }       for (i = 1; i < n; i++) {         if (len[pa[i]] >= 0 && len[i] < 0) {           len[i] = len[pa[i]] + 1;           if (fs[pa[i]] == 0) {             if (len[pa[i]] < cnt_ls) {               if (ls[len[pa[i]]] > pc[i])                 fs[i] = -1;               else if (ls[len[pa[i]]] < pc[i])                 fs[i] = 1;               else                 fs[i] = 0;             } else               fs[i] = 1;           } else             fs[i] = fs[pa[i]];           if (fs[i] < 0 || (fs[i] == 0 && len[i] != cnt_ls)) ans++;         }       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 50 + 7;   int ned[N][N];   string s[N];   void paint(const vector<pair<int, int> > &v) {     set<pair<int, int> > s;     queue<pair<int, int> > que;     map<pair<int, int>, int> cnt;     for (auto e : v) {       que.push(e);       s.insert(e);     }     const int dx[] = {2, 2, 1, 1, -1, -1, -2, -2};     const int dy[] = {1, -1, 2, -2, 2, -2, 1, -1};     int tot = 0;     while (!que.empty()) {       auto p = que.front();       que.pop();       tot++;       for (int i = (0); i < (8); i++) {         int x = p.first + dx[i];         int y = p.second + dy[i];         if (s.find(make_pair(x, y)) != s.end()) continue;         if (++cnt[make_pair(x, y)] == 4) {           s.insert({x, y});           que.push({x, y});         }       }     }     cout <<  sz(s)           <<   =   << (((int)(s).size())) <<   n ;     int des = ((int)(v).size()) * ((int)(v).size()) / 10;     cout <<  des           <<   =   << (des) <<   n ;   }   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(0);     int n;     cin >> n;     vector<pair<int, int> > v;     for (int i = (0); i < (n); i++) {       if (i & 1) v.push_back({3, i});       v.push_back({0, i});       if (((int)(v).size()) > n) break;     }     v.resize(n);     for (auto e : v) cout << e.first <<     << e.second <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long x, y, p, q;   bool check(long long t) {     return ((p * t >= x) && ((q * t - p * t) >= (y - x)));   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       scanf( %I64d%I64d%I64d%I64d , &x, &y, &p, &q);       long long l = 0, r = 1e9, mid;       long long ans = -1;       while (l <= r) {         mid = (l + r) / 2;         if (check(mid)) {           ans = mid;           r = mid - 1;         } else           l = mid + 1;       }       if (ans == -1)         printf( -1 n );       else         printf( %I64d n , ans * q - y);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   inline int add(int a, int b) {     a += b;     if (a >= mod) a -= mod;     return a;   }   inline int sub(int a, int b) {     a -= b;     if (a < 0) a += mod;     return a;   }   inline int mul(int a, int b) { return (a * 1ll * b) % mod; }   inline int power(int a, int b) {     int rt = 1;     while (b > 0) {       if (b & 1) rt = mul(rt, a);       a = mul(a, a);       b >>= 1;     }     return rt;   }   inline int inv(int a) { return power(a, mod - 2); }   const int N = 1e6 + 5;   vector<int> z_function(string s) {     int n = (int)s.length();     vector<int> z(n);     for (int i = 1, l = 0, r = 0; i < n; ++i) {       if (i <= r) z[i] = min(r - i + 1, z[i - l]);       while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i];       if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;     }     return z;   }   string a;   int mat[N][2], sum0[N], dp[N], sumdp[N];   void fill(string s, int ind) {     string s1 = s +  $  + a;     vector<int> v = z_function(s1);     int n1 = s.size(), n = a.size();     for (int i = 0; i < n; i++) mat[i][ind] = v[n1 + 1 + i];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout << setprecision(25);     string l, r;     cin >> a >> l >> r;     int n = a.size(), l1 = l.size(), r1 = r.size();     fill(l, 0);     fill(r, 1);     for (int i = 0; i < n; i++) {       if (i + 1 < l1) continue;       if (i > 0) sum0[i] = sum0[i - 1], sumdp[i] = sumdp[i - 1];       if (a[i] ==  0 ) sum0[i] = add(sum0[i], i - 1 < 0 ? 1 : dp[i - 1]);       int ind1 = -1, ind2 = -1;       ind1 = i - l1 + 1;       int x = mat[ind1][0];       if (x < l1 && a[ind1 + x] < l[x]) ind1--;       if (ind1 < 0) continue;       ind2 = i - r1 + 1;       if (ind2 < 0)         ind2 = 0;       else {         x = mat[ind2][1];         if (x != r1 && a[ind2 + x] > r[x]) ind2++;       }       if (ind2 > ind1) continue;       if (ind1 == ind2) {         if (ind1 == 0)           dp[i] = 1;         else           dp[i] = dp[ind1 - 1];         if (i - ind1 > 0 && a[ind1] ==  0 ) dp[i] = 0;       } else {         dp[i] = sub(sub(sumdp[ind1 - 1], (ind2 - 2 < 0 ? ind2 == 0 ? mod - 1 : 0                                                        : sumdp[ind2 - 2])),                     sub(sum0[ind1], (ind2 - 1 < 0 ? 0 : sum0[ind2 - 1])));         if (i == ind1 && a[i] ==  0 ) dp[i] = add(dp[i], i == 0 ? 1 : dp[i - 1]);       }       sumdp[i] = add(sumdp[i], dp[i]);     }     cout << dp[n - 1] << endl;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> x[200];   int y[200], n, i, j, k, a, b, c, s, A, B;   int main() {     scanf( %d , &n);     n *= 2;     for (i = 1; i <= n; i++) scanf( %d , &k), x[k].push_back(i);     for (i = 10; i <= 99; i++)       if (x[i].size() == 1) {         if (a > b)           y[x[i][0]] = 2, b++;         else           y[x[i][0]] = 1, a++;       }     s = a * b;     A = a;     B = b;     for (i = 10; i <= 99; i++)       if (x[i].size() > 1) {         s += a + b;         c++;         for (j = 0; j < x[i].size(); j++) {           if (A > B)             y[x[i][j]] = 2, B++;           else             y[x[i][j]] = 1, A++;         }       }     s += c * c;     printf( %d n , s);     for (i = 1; i <= n; i++) printf( %d  , y[i]);   }
#include <bits/stdc++.h>   #include <chrono>      using namespace std;      using ll           = long long;   using ld           = long double;   using pii          = pair<int, int>;   using pll          = pair<long, long>;   using vi           = vector<int>;   using vl           = vector<long long>;   using vb           = vector<bool>;   using vs           = vector<string>;   using vld          = vector<long double>;      #define pb             push_back   #define f              first   #define s              second   #define sz(a)          int((a).size())   #define all(a)         (a).begin(), (a).end()   #define rall(a)        (a).rbegin(), (a).rend()   #define sum(a)         ( accumulate((a).begin(), (a).end(), 0LL))   #define mine(a)        (*min_element((a).begin(), (a).end()))   #define maxe(a)        (*max_element((a).begin(), (a).end()))   #define mini(a)        ( min_element((a).begin(), (a).end()) - (a).begin())   #define maxi(a)        ( max_element((a).begin(), (a).end()) - (a).begin())   #define lowb(a, x)     ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())   #define uppb(a, x)     ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())   #define each(a, b)     for (auto &a: b)   #define yes            cout <<  YES  << endl   #define no             cout <<  NO   << endl      mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());      const ll mod = 1e9 + 7;      ll n, m, k, p, q, l, r, u, v, x, y, z;   // ll ans = 0;      void solve(int t = 1) {       cin >> n >> m;          vi a(n), b(n), c(m);       each(u, a) cin >> u;       each(u, b) cin >> u;       each(u, c) cin >> u;          vi ans(m, 0);          map<int, vi> mp;       for (int i = 0; i < m; i++) {           mp[c[i]].push_back(i);       }          for (int i = 0; i < n; i++) {           if (a[i] != b[i]) {               if (!mp[b[i]].empty()) {                   a[i] = b[i];                   ans[mp[b[i]].back()] = i + 1;                   mp[b[i]].pop_back();               } else {                   no;                   return;               }           }       }          if (a != b) {           no;           return;       }          if (ans[m - 1] == 0) {           bool flag = true;              for (int i = 0; i < n; i++) {               if (c[m - 1] == b[i]) {                   ans[m - 1] = i + 1;                   flag = false;                   break;               }           }              if (flag) {               no;               return;           }       }          each(u, ans) {           if (u == 0) u = ans[m - 1];       }          yes;       each(u, ans) cout << u <<    ;       cout << endl;   }      int main() {       ios_base::sync_with_stdio(false);       cin.tie(NULL);          int tc = 1;       cin >> tc;          for (int t = 1; t <= tc; t++) solve(t);          return 0;   }
#include <bits/stdc++.h>   using namespace std;   #define endl   n    typedef long long ll;   typedef pair<int, int> pii;   typedef pair<ll, ll> pll;   typedef tuple<int, int, int> tiii;   typedef tuple<ll, ll, ll> tlll;   const int INF = 100000000;   const ll INFINITE = 4500000000000000000;      int main(void) {    int t;    cin >> t;    while (t--) {     int s1, s2, s3, s4;     cin >> s1 >> s2 >> s3 >> s4;     if (min(s1, s2) < max(s3, s4) &&min(s3, s4) <max(s1, s2))      cout <<  YES  << endl;     else      cout <<  NO  << endl;       }   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1);   int main() {     int n;     double R, r;     double st;     while (scanf( %d %lf , &n, &R) != EOF) {       st = pi / (1.0 * n);       r = sin(st) * R / (1 - sin(st));       printf( %.7lf n , r);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[2000090];   int d[2000009][11];   int main() {     ios::sync_with_stdio(0);     for (int i = 1; i < 10; i++) a[i] = i;     for (int i = 1; i < 2000009; i++) {       int l = 1;       int g = i;       while (g != 0) {         if (g % 10 != 0) l *= (g % 10);         g /= 10;       }       for (int j = 1; j < 10; j++) d[i][j] = d[i - 1][j];       a[i] = a[l];       d[i][a[l]]++;     }     int q;     cin >> q;     while (q--) {       int x, y, z;       cin >> x >> y >> z;       cout << d[y][z] - d[x - 1][z] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m;     cin >> n >> m;     if (m == 0) {       cout << n <<     << n << endl;       return 0;     }     long long min = 0;     if (m * 2ll <= n) {       min = n - m * 2;     }     long long e = 1;     long long g = 2;     long long max = 0;     for (long long i = 2; i <= n; i++) {       if (e >= m) {         max = n - i;         break;       }       e += g;       g++;     }     cout << min <<     << max << endl;     return 0;   }
#include<bits/stdc++.h>   #define rep(i, n) for(int i = 0; i < n; i++)   using namespace std;   typedef long long ll;   const ll Mod = 1000000007;      int t;   int n;   ll x[500500];   ll sum_bit[70];      int main(){    ios::sync_with_stdio(false);    cin >> t;    while(t--){     cin >> n;     rep(i, n) cin >> x[i];     memset(sum_bit, 0, sizeof(sum_bit));     rep(b, 60) rep(i, n) sum_bit[b] = (sum_bit[b] + (x[i] & (1LL << b))) % Mod;     ll ans = 0;     rep(j, n){      ll sum_and = 0, sum_or = 0;      rep(b, 60){       if(x[j] & (1LL << b)) sum_and = (sum_and + sum_bit[b]) % Mod, sum_or = (sum_or + (1LL << b) % Mod * n % Mod) % Mod;       else sum_or = (sum_or + sum_bit[b]) % Mod;      }      ans = (ans + sum_and * sum_or) % Mod;     }     cout << ans << endl;    }    return 0;   }
#include <bits/stdc++.h>   int max(int a, int b) { return a > b ? a : b; }   int a[510][510], num[510], n, m, Q, ans, x, y;   void work(int pos) {     num[pos] = 0;     int f = 0;     for (int i = 1; i <= m; i++)       if (a[pos][i])         f++;       else         num[pos] = max(num[pos], f), f = 0;     num[pos] = max(num[pos], f);   }   int main() {     scanf( %d%d%d , &n, &m, &Q);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) scanf( %d , &a[i][j]);     for (int i = 1; i <= n; i++) work(i), ans = max(ans, num[i]);     for (int t = 1; t <= Q; t++) {       scanf( %d%d , &x, &y);       a[x][y] = a[x][y] ^ 1;       work(x);       ans = 0;       for (int i = 1; i <= n; i++) ans = max(ans, num[i]);       printf( %d n , ans);     }   }
#include <bits/stdc++.h>   int main() {     int n, start;     char str[60];     scanf( %s , str);     n = strlen(str);     n = n % 2 ? n / 2 : n / 2 - 1;     printf( %c , str[n]);     for (int i = 1; i <= n; i++) printf( %c%c , str[n + i], str[n - i]);     if (strlen(str) % 2 == 0 && strlen(str) > 1)       printf( %c , str[strlen(str) - 1]);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, cntx = 0, cntX = 0, c = 0;     cin >> n;     string s;     cin >> s;     for (int i = 0; i < n; i++) {       if (s[i] ==  x )         cntx++;       else         cntX++;     }     int i = 0;     if (cntx > cntX) {       while (cntx != cntX) {         if (s[i] ==  x ) {           s[i] =  X ;           cntx--;           c++;           cntX++;         }         i++;       }     } else {       while (cntx != cntX) {         if (s[i] ==  X ) {           s[i] =  x ;           cntX--;           cntx++;           c++;         }         i++;       }     }     cout << c << endl << s << endl;     return 0;   }
#include <bits/stdc++.h>   const double EPS = 1e-9;   const int INT_INF = 1 << 31 - 1;   const long long I64_INF = 1ll << 63 - 1ll;   const double PI = acos(-1.0);   using namespace std;   vector<int> r;   string second;   void ReadTable(int id, int& FinalId);   string GetTag(int id) {     string res =   ;     id++;     while (second[id] !=  > ) res += second[id], id++;     return res;   }   void ReadTd(int id, int& FinalId) {     string tag = GetTag(id);     while (tag !=  /td ) {       int NewId;       ReadTable(id + 7, NewId);       id = NewId;       tag = GetTag(id);     }     FinalId = id + 5;   }   int ReadTr(int id, int& FinalId) {     int res = 0;     string tag = GetTag(id);     while (tag !=  /tr ) {       int NewId;       ReadTd(id + 4, NewId);       id = NewId;       res++;       tag = GetTag(id);     }     FinalId = id + 5;     return res;   }   void ReadTable(int id, int& FinalId) {     int res = 0;     string tag = GetTag(id);     while (tag !=  /table ) {       int NewId;       res += ReadTr(id + 4, NewId);       id = NewId;       tag = GetTag(id);     }     FinalId = id + 8;     r.push_back(res);   }   int main() {     char c;     second.clear();     while (scanf( %c , &c) >= 1)       if (c !=     && c !=   n ) second += c;     int loose;     ReadTable(7, loose);     sort(r.begin(), r.end());     for (int i = 0; i < (int)r.size(); i++) printf( %d  , r[i]);     return 0;   }