malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int B = 31;   const int N = 107;   int a[N];   bool vis[1000007];   map<int, int> state;   map<int, int> sgn;   int tc = -1;   inline int grrr(int mask) {     if (mask < 2) return 0;     auto it = sgn.find(mask);     if (it != sgn.end()) return it->second;     vector<int> to_clear;     for (int i = 1; i < B; ++i) {       int small = (mask & ((1 << i) - 1));       int large = (mask >> i);       int nmask = (small | large);       if (nmask == mask) continue;       int val = grrr(nmask);       to_clear.push_back(val);     }     for (int x : to_clear) vis[x] = true;     int ret = 0;     while (vis[ret]) ++ret;     for (int x : to_clear) vis[x] = false;     return sgn[mask] = ret;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     for (int i = 0; i < n; ++i) {       int x = a[i];       for (int k = 2; k * k <= x; ++k) {         int cnt = 0;         while (x % k == 0) {           x /= k;           ++cnt;         }         if (cnt) state[k] |= (1 << cnt);       }       if (x > 1) state[x] |= 2;     }     int res = 0;     for (auto &qq : state) {       res ^= grrr(qq.second);     }     cout << (res ?  Mojtaba  :  Arpa ) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool isprime[1000001];   void sieve() {     for (long long i = 0; i <= 1000001; i++) {       isprime[i] = true;     }     isprime[0] = false;     isprime[1] = false;     for (long long i = 2; i * i <= 1000001; i++) {       if (isprime[i] == true) {         for (long long j = i * i; j <= 1000001; j = j + i) {           isprime[j] = false;         }       }     }   }   long long gcd(long long a, long long b) {     if (a < b) {       swap(a, b);     }     if (b == 0) {       return a;     }     return gcd(b, a % b);   }   bool comparen(pair<long long, long long> a, pair<long long, long long> b) {     return a.second < b.second;   }   bool comparem(pair<long long, long long> a, pair<long long, long long> b) {     return a.first > b.first;   }   void remove(long long n, char x, string s) { ; }   void solve() {     long long t = 1;     while (t--) {       long long n;       cin >> n;       long long a[n];       for (long long i = 0; i < n; i++) {         cin >> a[i];       }       long long i = 0;       while (i < n - 1 && a[i] <= a[i + 1]) {         i++;       }       long long k = i + 1;       i++;       while (i < n - 1 && a[i] <= a[i + 1]) {         i++;       }       if (i == n) {         cout << 0 << endl;       } else if (i != n - 1 || a[0] < a[n - 1]) {         cout << -1 << endl;       } else {         cout << n - k << endl;       }     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long solve(long long a, long long b, long long n, long long l,                   long long r) {     if (b <= l || r <= a) return 0;     if (a <= l && r <= b) return n;     long long mid = (l + r) / 2;     long long lch = solve(a, b, n / 2, l, mid);     long long rch = solve(a, b, n / 2, mid + 1, r);     long long ret = lch + rch;     if (a <= mid && mid < b) ret += n & 1;     return ret;   }   int main() {     long long n, l, r;     scanf( %lld%lld%lld , &n, &l, &r);     long long p = 1;     while (p <= n) {       p <<= 1;     }     long long ans = solve(l - 1, r, n, 0, p - 1);     printf( %lld n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n, S;     scanf( %d , &n);     scanf( %d , &S);     string st;     map<int, int> b, s;     for (int i = 0; i < n; i++) {       cin >> st;       int p, q;       scanf( %d , &p);       scanf( %d , &q);       if (st[0] ==  B ) {         b[p] += q;       } else {         s[p] += q;       }     }     int ct = max(0, (int)s.size() - S);     for (map<int, int>::reverse_iterator it = s.rbegin(); it != s.rend(); it++) {       if (ct) {         ct--;         continue;       }       cout <<  S   << it->first <<     << it->second << endl;     }     ct = 0;     for (map<int, int>::reverse_iterator it = b.rbegin(); it != b.rend(); it++) {       cout <<  B   << it->first <<     << it->second << endl;       ct++;       if (ct == S) break;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mn = 1005;   int n, v[mn];   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     for (int x = 0; x < n; ++x) cin >> v[x];     int ans = 0;     for (int x = 0; x < n; ++x) {       if (v[x] == 0) continue;       while (v[x] == 1 && x < n) ++ans, ++x;       ++ans;     }     if (ans != 0) --ans;     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e6;   int q, lstAns, flag;   long long m;   struct point {     long long x, y;     point(long long x, long long y) : x(x), y(y) {}     inline bool operator<(const point &a) const {       if (flag) return y < a.y;       return x < a.x;     }     inline point operator-(const point &a) const {       return point(x - a.x, y - a.y);     }     inline long long cross(const point &a) const { return x * a.y - y * a.x; }   };   set<point> mag;   inline int addMod(int a, int b) { return (a += b) >= mod ? a - mod : a; }   inline long long quickpow(long long base, long long pw) {     long long ret = 1;     while (pw) {       if (pw & 1) ret = ret * base % mod;       base = base * base % mod, pw >>= 1;     }     return ret;   }   template <class T>   inline void read(T &x) {     x = 0;     char ch = getchar(), w = 0;     while (!isdigit(ch)) w = (ch ==  - ), ch = getchar();     while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();     x = w ? -x : x;     return;   }   int main() {     int opt, x, y;     read(q), read(m);     mag.emplace(0, 0);     for (register int i = 1; i <= q; ++i) {       read(opt), read(x), read(y);       x = (x + lstAns) % mod + 1, y = (y + lstAns) % mod + 1;       if (opt == 1) {         point tmp(y, x);         auto r = mag.lower_bound(point(y + 1, 0)), l = prev(r);         if (r != mag.end() && (tmp - *l).cross(*r - *l) >= 0) continue;         while (l != mag.begin()) {           if ((*l - *prev(l)).cross(tmp - *prev(l)) < 0) break;           mag.erase(l--);         }         while (r != mag.end() && r->y <= x) mag.erase(r++);         while (r != mag.end() && next(r) != mag.end()) {           if ((*r - tmp).cross(*next(r) - tmp) < 0) break;           mag.erase(r++);         }         mag.insert(tmp);       } else {         flag = 1;         auto r = mag.lower_bound(point(0, ceil((double)y / x))), l = prev(r);         if (r == mag.end()) {           printf( NO n ), flag = 0;           continue;         }         if ((y - l->y * x) * (r->x - l->x) + l->x * (r->y - l->y) * x <=             m * (r->y - l->y))           printf( YES n ), lstAns = i;         else           printf( NO n );         flag = 0;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       long long int n, y, k;       cin >> n >> y >> k;       if (n < y) swap(n, y);       if (k < n) {         cout <<  -1  << endl;         continue;       }       if (n % 2 == 1 && y % 2 == 1 && k % 2 == 1) {       } else if (n % 2 == 0 && y % 2 == 1 && k % 2 == 1) {         k = k - 1;         y = y - 1;       } else if (n % 2 == 0 && y % 2 == 0 && k % 2 == 1) {         k -= 2;         n -= 1;         y -= 1;       } else if (n % 2 == 1 && y % 2 == 0 && k % 2 == 1) {         n = n - 1;         k = k - 1;       } else if (n % 2 == 0 && y % 2 == 1 && k % 2 == 0) {         n = n - 1;         k = k - 1;       } else if (n % 2 == 1 && y % 2 == 1 && k % 2 == 0) {         k = k - 2;         n = n - 1;         y = y - 1;       } else if (n % 2 == 1 && y % 2 == 0 && k % 2 == 0) {         y = y - 1;         k = k - 1;       } else {       }       cout << k << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }   const int inf = 1 << 29;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       long long a, b, c, d;       cin >> a >> b >> c >> d;       a -= b;       if (a <= 0)         cout << b << endl;       else {         if (c <= d) {           cout << -1 << endl;         } else {           long long ss = c - d;           long long nss = a / ss;           if (a % ss != 0) nss++;           cout << b + nss * c << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> e[3005];   int a, b, step[3005][3005], N, M, p[5], res = -1, ans[5], q[3005], qe,                                           st[3005][5], ed[3005][5];   inline void bfs(int x) {     step[x][x] = 0;     qe = 0;     q[qe++] = x;     for (int i = 0; i < qe; i++) {       int ff = q[i];       for (vector<int>::iterator it = e[ff].begin(); it != e[ff].end(); it++)         if (step[x][*it] == -1) {           step[x][*it] = step[x][ff] + 1;           q[qe++] = *it;         }     }   }   void upDate() {     for (int i = 1; i <= 4; i++)       for (int j = 1; j <= 4; j++)         if (i != j && p[i] == p[j]) return;     int l = 0;     for (int i = 1; i < 4; i++) l += step[p[i]][p[i + 1]];     if (l > res) {       res = l;       for (int i = 1; i <= 4; i++) ans[i] = p[i];     }   }   int main() {     memset(step, -1, sizeof(step));     cin >> N >> M;     while (M--) {       cin >> a >> b;       if (a != b) e[a].push_back(b);     }     for (int i = 1; i <= N; i++) bfs(i);     for (int i = 1; i <= N; i++) {       for (int j = 0; j < 5; j++) st[i][j] = ed[i][j] = i;       for (int j = 1; j <= N; j++) {         if (j == i) continue;         for (int k = 3; k > -1; k--) {           if (step[i][st[i][k]] < step[i][j])             st[i][k + 1] = st[i][k], st[i][k] = j;           if (step[ed[i][k]][i] < step[j][i])             ed[i][k + 1] = ed[i][k], ed[i][k] = j;         }       }     }     for (int i = 1; i <= N; i++)       for (int j = 1; j <= N; j++)         if (i != j && step[i][j] > 0)           for (int u = 0; u < 4; u++)             for (int k = 0; k < 4; k++) {               p[1] = ed[i][u], p[2] = i, p[3] = j, p[4] = st[j][k];               upDate();             }     for (int i = 1; i <= 4; i++) cout << ans[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = (1ll << 60);   int n, k, p;   int a[2005], b[2005];   long long dp[2005][2005];   long long rec(int pos, int key) {     if (pos == n) {       return 0;     }     if (key == k) return inf;     long long &ret = dp[pos][key];     if (ret != -1) return ret;     long long sum = abs(a[pos] - b[key]) + abs(b[key] - p);     ret = max(sum, rec(pos + 1, key + 1));     ret = min(ret, rec(pos, key + 1));     return ret;   }   int main() {     cin >> n >> k >> p;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < k; i++) cin >> b[i];     sort(a, a + n);     sort(b, b + k);     memset(dp, -1, sizeof dp);     cout << rec(0, 0) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<int> adj[n], in[n];     int ot[n];     for (int i = 0; i < n; i++) ot[i] = 0;     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       x--;       y--;       adj[x].push_back(y);       in[y].push_back(x);       ot[x]++;     }     int vis[n];     for (int i = 0; i < n; i++) {       vis[i] = 0;     }     int st, en;     cin >> st >> en;     st--;     en--;     deque<int> q;     int dp[n];     for (int i = 0; i < n; i++) dp[i] = 10000000;     dp[en] = 0;     q.push_back(en);     while (!q.empty()) {       int u = q.front();       q.pop_front();       if (vis[u] == 1) continue;       vis[u] = 1;       for (int i = 0; i < in[u].size(); i++) {         int v = in[u][i];         ot[v]--;         if (ot[v] == 0) {           if (dp[v] > dp[u]) {             dp[v] = dp[u];             q.push_front(v);           }         } else {           if (dp[v] > dp[u] + 1) {             dp[v] = dp[u] + 1;             q.push_back(v);           }         }       }     }     if (dp[st] != 10000000)       cout << dp[st];     else       cout << -1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   long long n, a[N], subtree[N], total, ans, initCost;   vector<int> g[N];   void costfromRoot(int v, int prnt, int d) {     initCost += d * a[v];     subtree[v] += a[v];     for (int u : g[v])       if (u != prnt) {         costfromRoot(u, v, d + 1);         subtree[v] += subtree[u];       }   }   void dfs(int v, int prnt, long long res) {     ans = max(ans, res);     for (int u : g[v])       if (u != prnt) {         dfs(u, v, res + total - 2 * subtree[u]);       }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       total += a[i];     }     for (int i = 0; i < n - 1; ++i) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     costfromRoot(1, -1, 0);     dfs(1, -1, initCost);     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct point {     int x, y;   };   struct ConvexHull {     vector<point> hull;     int m;     ConvexHull() : m(0) { hull.clear(); }     bool ccw(point x, point y, point z) {       return ((y.x - x.x) * (z.y - x.y) > (y.y - x.y) * (z.x - x.x));     }     void MakeHull(int n, vector<point> a) {       hull.clear();       if (!n) return;       int x = 0;       for (int i = 0; i < n; i++)         if ((a[i].y == a[x].y) ? a[i].x < a[x].x : a[i].y < a[x].y) x = i;       swap(a[0], a[x]);       hull.push_back({a[0].x, a[0].y + 1});       hull.push_back(a[0]);       sort(a.begin() + 1, a.begin() + n, [=](point x, point y) {         return (((x.y - a[0].y) * (y.x - a[0].x)) <                 (x.x - a[0].x) * (y.y - a[0].y));       });       m = 1;       for (int i = 1; i < n; i++) {         while (!ccw(hull[m - 1], hull[m], a[i]))           if (m > 1)             hull.pop_back(), m--;           else if (i + 1 == n)             break;           else             i++;         hull.push_back(a[i]);         m++;       }       hull.erase(hull.begin());     }   };   int n;   int r;   vector<point> v;   ConvexHull cw;   int ma = 0;   vector<point> rez;   void rec(int l, int rem, int s, point r) {     if (!rem) {       int d = s * n - r.x * r.x - r.y * r.y;       if (d > ma) {         ma = d;         rez = v;       }       return;     }     if (l == cw.m) return;     rec(l + 1, rem, s, r);     v.push_back(cw.hull[l]);     r = {r.x + v.back().x, r.y + v.back().y};     s += v.back().x * v.back().x + v.back().y * v.back().y;     rec(l, rem - 1, s, r);     v.pop_back();   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> r;     for (int i = 0; i * i <= r * r; i++)       for (int j = 0; j * j + i * i <= r * r; j++) {         v.push_back({i, j});         if (i) v.push_back({-i, j});         if (j) v.push_back({i, -j});         if (i - j) v.push_back({j, i});         if (i * j) v.push_back({-i, -j});       }     cw.MakeHull(v.size(), v);     v.clear();     rec(0, n, 0, {0, 0});     cout << ma <<   n ;     for (int i = 0; i < n; i++) cout << rez[i].x <<     << rez[i].y <<   n ;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int N = 2e5 + 10;   vector<int> g[N];   int type[N];   bool noleaf = 1;   int cnt = 0;   void dfs(int v, int p) {     for (auto u : g[v]) {       if (u == p) continue;       dfs(u, v);       if (type[u] == 0) {         type[v] = 1;         if (v == 1) noleaf = 0;       }     }     if (v != 1) cnt += type[v];   }   void solve() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       g[i].clear();       cnt = 0;       type[i] = 0;       noleaf = 1;     }     for (int i = 1; i < n; i++) {       int a, b;       cin >> a >> b;       g[a].push_back(b);       g[b].push_back(a);     }     dfs(1, 0);     cout << n - 2 * cnt - 1 + noleaf <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   void ga(int N, int *A) {     for (int i(0); i < N; i++) scanf( %d , A + i);   }   map<int, vector<pair<int, int> > > T[4];   int N, M, a, b, f[10], C[100005];   int main(void) {     scanf( %d%d , &N, &M);     for (int i(0); i < M; i++)       scanf( %d%d , &a, &b), T[0][a].push_back({b, i}), T[1][b].push_back({a, i}),           T[2][a + b].push_back({a, i}), T[3][a - b].push_back({a, i});     for (int i(0); i < 4; i++)       for (auto &h : T[i]) {         sort(h.second.begin(), h.second.end());         a = 0;         for (auto &w : h.second) C[w.second] += a, a = 1;         reverse(h.second.begin(), h.second.end());         a = 0;         for (auto &w : h.second) C[w.second] += a, a = 1;       }     for (int i(0); i < M; i++) ++f[C[i]];     for (int i(0); i < 9; i++) printf( %d  , f[i]);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, i, lki, kills = 0, temp;     long long* L = new long long[1000001];     cin >> n;     for (i = 0; i < n; i++) {       scanf( %ld , &L[i]);     }     lki = (n - 1) - L[n - 1];     kills += min(L[n - 1], n - 1);     for (i = n - 2; i > 0; i--) {       if (lki <= 0) break;       if (L[i] > i) L[i] = i;       temp = i - L[i];       if (temp < lki) {         if (i < lki) {           kills += L[i];         } else {           temp = L[i] - (i - lki);           kills += temp;         }         lki = i - L[i];       }     }     cout << n - kills << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, k, temp;   int main() {     scanf( %d%d%d , &n, &m, &k);     if (n % 2 == 0 || m < (n / 2 + 1)) {       printf( 0 n );       return 0;     }     long long minA = (m / (n / 2 + 1)) * k;     for (int i = 0; i < n; i++) {       scanf( %d , &temp);       if (i % 2 == 0 && temp < minA) minA = temp;     }     printf( %d n , minA);     return 0;   }
#include <bits/stdc++.h>   const double pi = acos(-1.0);   const double eps = 1e-9;   using namespace std;   const long long MOD = 998244353;   const int N = 2e5 + 10;   long long mult(long long x, long long y) {     x %= MOD;     y %= MOD;     return x * y % MOD;   }   long long bin_pow(long long x, long long n) {     long long res = 1;     while (n) {       if (n & 1) res = mult(res, x);       n >>= 1;       x = mult(x, x);     }     return res;   }   long long inv(long long x) { return bin_pow(x, MOD - 2); }   long long add(long long x, long long y) {     x += y;     if (x >= MOD) x -= MOD;     return x;   }   int n, m;   long long d[N], prefD[N];   long long get(int l, int r) { return (prefD[r] - prefD[l] + MOD) % MOD; }   void solve() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> d[i];     }     sort(d, d + n);     for (int i = 1; i <= n; i++) {       prefD[i] = prefD[i - 1] + d[i - 1];     }     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       int cnt = d + n - lower_bound(d, d + n, b);       int res = 0;       if (cnt >= a) {         res = mult(mult(cnt - a, inv(cnt)), get(n - cnt, n));         res = add(res, mult(mult(cnt - a + 1, inv(cnt + 1)), get(0, n - cnt)));       }       cout << res <<   n ;     }   }   int main() {     ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);     cout.setf(ios::fixed), cout.precision(9);     int step = 1;     for (int i = 0; i < step; i++) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   set<int> s;   int solve(vector<int> v, int k, int n) {     s.clear();     for (int i = 0; i < k; i++) s.insert(v[i]);     if (s.size() == k && *(s.begin()) == 1 && *(s.rbegin()) == k) {       s.clear();       for (int i = k; i < n; i++) s.insert(v[i]);       if (s.size() == n - k && *(s.begin()) == 1 && *(s.rbegin()) == (n - k))         return 1;       else         return -1;     } else       return -1;   }   int main() {     int t, n, m;     cin >> t;     vector<int> ans;     while (t--) {       cin >> n;       vector<int> a(n);       m = 0;       ans.clear();       for (int i = 0; i < n; i++) {         cin >> a[i];         if (a[i] > m) m = a[i];       }       if (m > n - 1) {         cout <<  0 n ;         continue;       } else {         if (solve(a, m, n) != -1) ans.push_back(m);         if (solve(a, n - m, n) != -1 && m != n - m) ans.push_back(n - m);         cout << ans.size() << endl;         if (ans.size()) {           for (auto tl = ans.begin(); tl != ans.end(); tl++)             cout << *tl <<     << n - *tl << endl;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   bool compare(const pair<int, int>& a, const pair<int, int>& b) {     return a.second < b.second;   }   bool not_fixed(vector<int>& v) {     for (int i = 1; i < v.size() - 1; i++) {       if (v[i] == 0 && v[i - 1] == 1 && v[i + 1] == 1) return true;     }     return false;   }   int main() {     int n;     cin >> n;     vector<int> v(n);     for (int i = 0; i < n; i++) {       cin >> v[i];     }     int ans = 0;     while (not_fixed(v)) {       map<int, int> wo;       for (int i = 1; i < n - 1; i++) {         if (v[i] == 0 && v[i - 1] == 1 && v[i + 1] == 1) {           wo[i - 1]++;           wo[i + 1]++;         }       }       int maxi = max_element(wo.begin(), wo.end(), compare)->first;       v[maxi] = 0;       ans++;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, i, j = 0, r = 0, c = 1;     cin >> n;     long long matrix[n][n];     for (i = 0; i < n - 1; i++) {       for (j = 0; j < n - 1; j++) {         matrix[i][j] = (i + j) % (n - 1) + 1;       }     }     for (i = 0; i < n - 1; i++) {       matrix[i][n - 1] = matrix[n - 1][i] = matrix[i][i];       matrix[i][i] = 0;     }     matrix[n - 1][n - 1] = 0;     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) {         cout << matrix[i][j] <<    ;       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int f(string s) {     int ans = 0;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  1 ) {         ans++;       }     }     return ans;   }   int main() {     string a, b;     cin >> a >> b;     int c1 = f(a);     if (c1 % 2 != 0) {       c1++;     }     if (c1 >= f(b)) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200002, SQ = 450;   int n, c, a[N], first[N];   long long sum[SQ];   bool solve() {     int x = c;     for (int i = x; i >= 1; --i) {       i = min(i, x);       if (!sum[i / SQ]) {         i = i / SQ * SQ;         continue;       }       if (sum[i / SQ] <= x)         x -= sum[i / SQ], i = i / SQ * SQ;       else         x -= min(first[i], x / i) * i;       if (!x) break;     }     return x > 0;   }   bool check(int i) {     ++first[i];     sum[i / SQ] += i;     bool fail = solve();     --first[i];     sum[i / SQ] -= i;     return fail;   }   int main() {     scanf( %d%d , &c, &n);     for (int i = 1; i <= n; ++i)       scanf( %d , &a[i]), ++first[a[i]], sum[a[i] / SQ] += a[i];     for (int i = 1; i <= c; ++i)       if (check(i)) return cout << i, 0;     cout <<  Greed is good ;   }
#include<bits/stdc++.h>   using namespace std;   int main(){    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);    int t;    cin >> t;    while(t--){     int n ; cin >> n;     vector<int> ans(n+1,1);     string str; cin >> str;     int cnt=0;     char now=str[0];     for(int i=0 ; i<n ; ++i){      if(str[i] != now) ++cnt , now = str[i];      else now = str[i] , cnt = 1;      if(now ==  L ) ans[i+1] += cnt;     }     now = str[n-1];     for(int i=n-1 ; i>=0 ; --i){      if(str[i] != now) ++cnt , now = str[i];      else now = str[i] , cnt = 1;      if(now ==  R ) ans[i] += cnt;     }     for(int i=0 ; i<=n ; ++i){      cout << ans[i];      if(i == n) cout <<   n ;      else cout <<    ;     }    }   }