malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   #pragma GCC optimize( unroll-loops )   using namespace std;   const long double eps = 1e-7;   const int inf = 1000000010;   const long long INF = 10000000000000010LL;   const int mod = 1000000007;   const int MAXN = 100010, LOG = 20;   int n, m, k, u, v, x, y, t, a, b, ans;   bool dead[MAXN];   string A;   vector<vector<int>> out;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> A;     n = A.size();     while (1) {       int i = 0, j = n - 1;       vector<int> v1, v2;       while (i < j) {         while (i < j && (A[i] ==  )  || dead[i])) i++;         while (i < j && (A[j] ==  (  || dead[j])) j--;         if (i >= j || A[i] ==  )  || A[j] ==  ( ) break;         v1.push_back(i++);         v2.push_back(j--);       }       if (v1.empty()) break;       reverse(v2.begin(), v2.end());       for (int i : v2) v1.push_back(i);       for (int i : v1) dead[i] = 1;       out.push_back(v1);     }     cout << out.size() <<   n ;     for (auto vec : out) {       cout << vec.size() <<   n ;       for (int i : vec) cout << i + 1 <<    ;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &x) {     register T c = getchar();     x = 0;     int t = 0;     if (c ==  - ) t = 1, c = getchar();     for (; (c < 48 || c > 57); c = getchar())       ;     for (; c > 47 && c < 58; c = getchar()) {       x = (x << 1) + (x << 3) + c - 48;     }     if (t) x = -x;   }   int main() {     int n, Max = 0;     read(n);     string str;     cin >> str;     bool visited[250] = {0};     for (int i = 0; i < n; i++) {       if (str[i] >=  a  && !visited[i]) {         set<char> s;         visited[i] = 1;         s.insert(str[i]);         for (int j = i + 1; j < n; j++) {           if (str[j] <=  Z ) break;           visited[j] = 1;           s.insert(str[j]);         }         if (Max < s.size()) Max = s.size();       }     }     cout << Max;   }
#include <bits/stdc++.h>   const int INF = 1e9;   using namespace std;   int dx[] = {-1, 1, 0, 0};   int dy[] = {0, 0, -1, 1};   bool vis[1005][1005], cvis[50];   vector<pair<int, int> > cc[50];   int m, n, k, a[1005][1005], D[45][1005][1005];   void DFS(int c) {     memset(vis, 0, sizeof(vis));     memset(cvis, 0, sizeof(cvis));     for (int i = 1; i <= m; i++)       for (int j = 1; j <= n; j++) D[c][i][j] = 4000;     queue<pair<int, int> > Q;     for (int i = 0; i < cc[c].size(); i++) {       Q.push(cc[c][i]);       vis[cc[c][i].first][cc[c][i].second] = 1;       D[c][cc[c][i].first][cc[c][i].second] = 0;     }     cvis[c] = 1;     int first, second, xx, yy;     while (!Q.empty()) {       first = Q.front().first;       second = Q.front().second;       Q.pop();       for (int j = 0; j < 4; j++) {         xx = first + dx[j];         yy = second + dy[j];         if (xx < 1 || yy < 1 || xx > m || yy > n) continue;         if (!vis[xx][yy]) {           vis[xx][yy] = 1;           D[c][xx][yy] = D[c][first][second] + 1;           Q.push(pair<int, int>(xx, yy));         }       }       if (!cvis[a[first][second]]) {         cvis[a[first][second]] = 1;         for (int i = 0; i < cc[a[first][second]].size(); i++) {           xx = cc[a[first][second]][i].first;           yy = cc[a[first][second]][i].second;           if (!vis[xx][yy]) {             vis[xx][yy] = 1;             D[c][xx][yy] = D[c][first][second] + 1;             Q.push(pair<int, int>(xx, yy));           }         }       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> m >> n >> k;     for (int i = 1; i <= m; i++)       for (int j = 1; j <= n; j++) {         cin >> a[i][j];         cc[a[i][j]].push_back(pair<int, int>(i, j));       }     for (int i = 1; i <= k; i++) DFS(i);     int ans = INF, q, r1, r2, c1, c2;     cin >> q;     while (q--) {       cin >> r1 >> c1 >> r2 >> c2;       ans = abs(r2 - r1) + abs(c1 - c2);       for (int i = 1; i <= k; i++) {         ans = min(ans, D[i][r1][c1] + D[i][r2][c2] + 1);       }       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   char in[4][4];   int oc = 0, xc = 0;   int whowin() {     int i, j;     int ret = 0;     for (i = 0; i < 3; i++) {       for (j = 0; j < 3; j++) {         if (in[i][j] != in[i][0]) break;       }       if (j == 3 && in[i][0] !=  . ) {         if (in[i][0] ==  0 )           ret |= 2;         else           ret |= 1;       }       for (j = 0; j < 3; j++) {         if (in[j][i] != in[0][i]) break;       }       if (j == 3 && in[0][i] !=  . ) {         if (in[0][i] ==  0 )           ret |= 2;         else           ret |= 1;       }     }     for (j = 0; j < 3; j++) {       if (in[j][j] != in[0][0]) break;     }     if (j == 3 && in[0][0] !=  . ) {       if (in[0][0] ==  0 )         ret |= 2;       else         ret |= 1;     }     for (j = 0; j < 3; j++) {       if (in[j][2 - j] != in[0][2]) break;     }     if (j == 3 && in[0][2] !=  . ) {       if (in[0][2] ==  0 )         ret |= 2;       else         ret |= 1;     }     return ret;   }   int main() {     int i, j;     for (i = 0; i < 3; i++) scanf( %s , in[i]);     for (i = 0; i < 3; i++) {       for (j = 0; j < 3; j++) {         if (in[i][j] ==  0 )           oc++;         else if (in[i][j] ==  X )           xc++;       }     }     try {       bool flag = 0;       bool cand[2] = {0, 0};       if (xc != oc && xc != oc + 1) throw  illegal ;       if (xc == 0 && oc == 0) throw  first ;       for (i = 0; i < 3; i++) {         for (j = 0; j < 3; j++) {           char c = in[i][j];           in[i][j] =  . ;           int f = whowin();           in[i][j] = c;           if (!f) {             flag = 1;             if (c ==  0 )               cand[1] = 1;             else if (c ==  X )               cand[0] = 1;           }         }       }       if (!flag) throw  illegal ;       if (xc == oc) {         if (cand[1]) {           if (whowin() == 2) throw  the second player won ;           throw  first ;         } else           throw  illegal ;       } else {         if (cand[0]) {           if (whowin() == 1) throw  the first player won ;           if (xc + oc == 9)             throw  draw ;           else             throw  second ;         } else           throw  illegal ;       }     } catch (const char* s) {       puts(s);     }   }
#include <bits/stdc++.h>   using namespace std;   const long double EPS = (long double)1e-7;   const long double PI = acos(0) * 2;   bool isZero(const long double& x) { return abs(x) <= EPS; }   int sign(const long double& x) { return isZero(x) ? 0 : (0 < x ? 1 : -1); }   long long gcd(long long a, long long b) {     for (; b; a %= b, swap(a, b)) {     }     return abs(a);   }   pair<long long, long long> operator+(const pair<long long, long long>& a,                                        const pair<long long, long long>& b) {     return pair<long long, long long>(a.first + b.first, a.second + b.second);   }   pair<long long, long long> operator-(const pair<long long, long long>& a,                                        const pair<long long, long long>& b) {     return pair<long long, long long>(a.first - b.first, a.second - b.second);   }   pair<long long, long long> operator*(const pair<long long, long long>& a,                                        const long long& b) {     return pair<long long, long long>(a.first * b, a.second * b);   }   long long operator*(const pair<long long, long long>& a,                       const pair<long long, long long>& b) {     return a.first * b.second - b.first * a.second;   }   long long ccw(const pair<long long, long long>& a,                 const pair<long long, long long>& b,                 const pair<long long, long long>& c) {     return a * b + b * c + c * a;   }   void fg(vector<int> G[], int a, int b) {     G[a].emplace_back(b);     G[b].emplace_back(a);   }   void fg(vector<pair<int, int> > G[], int a, int b, int c) {     G[a].emplace_back(b, c);     G[b].emplace_back(a, c);   }   long long A, B, C;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> A >> B >> C;     if (!A && !B) {       puts(C ?  0  :  -1 );       exit(0);     }     if (!A) {       printf( 1 n%.10lf n , double(-C) / B);       exit(0);     }     long long D = B * B - 4 * A * C;     if (D < 0) {       puts( 0 );       exit(0);     }     if (!D) {       printf( 1 n%.10lf n , double(-B) / A / 2);       exit(0);     }     if (A < 0) {       A = -A;       B = -B;       C = -C;     }     printf( 2 n%.10lf n%.10lf n , double(-B - sqrt(D)) / A / 2,            double(-B + sqrt(D)) / A / 2);     return 0;   }
#include <bits/stdc++.h>   const int INT_INF = 0x3f3f3f3f;   const int INT_M_INF = 0x7f7f7f7f;   const long long LL_INF = 0x3f3f3f3f3f3f3f3f;   const long long LL_M_INF = 0x7f7f7f7f7f7f7f7f;   const double pi = acos(-1.0);   using namespace std;   inline void debug(char ch) {     for (int __ii = 0; __ii < 20; ++__ii) putchar(ch);     printf(  n );   }   const double eps = 1e-8;   inline int dcmp(double a, double b) {     if (fabs(a - b) < eps) return 0;     return a < b ? -1 : 1;   }   const long long MOD = 1e9 + 7;   const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};   const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};   const int MAXN = 1000 + 10;   const int MAXT = 10000 + 10;   char s[MAXN], t[MAXN];   int len;   char sta[100];   bool vis[100];   bool solve() {     for (int i = 0; i < len; ++i)       if (s[i] != t[i]) {         if (vis[s[i] -  a ] || vis[t[i] -  a ]) return false;         if (sta[s[i] -  a ] != 0) {           if (sta[s[i] -  a ] != t[i]) return false;         } else if (sta[t[i] -  a ] != 0) {           if (sta[t[i] -  a ] != s[i]) return false;         } else {           sta[s[i] -  a ] = t[i];           sta[t[i] -  a ] = s[i];         }       } else {         if (sta[s[i] -  a ] != 0) return false;         vis[s[i] -  a ] = true;       }     return true;   }   vector<pair<char, char> > vec;   int main() {     while (scanf( %s%s , s, t) == 2) {       memset(sta, 0, sizeof(sta));       memset(vis, false, sizeof vis);       vec.clear();       len = strlen(s);       bool ans = solve();       if (ans) {         for (int i = 0; i < 26; ++i)           if (sta[i] != 0) {             vec.push_back(pair<char, char>( a  + i, sta[i]));             sta[sta[i] -  a ] = 0;           }         printf( %d n , (int)((vec).size()));         for (int i = 0; i < (int)((vec).size()); ++i)           printf( %c %c n , ((vec[i]).first), ((vec[i]).second));       } else         printf( -1 n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dx[] = {1, -1, 0, 0};   int dy[] = {0, 0, -1, 1};   int tt[1016][1016];   int hh[1016][1016];   int n, m;   int ex, ey;   queue<int> q;   queue<int> p;   void bfs() {     while (!p.empty()) {       int x = p.front();       int y = q.front();       p.pop();       q.pop();       for (int i = 0; i < 4; i++) {         int nx = x + dx[i];         int ny = y + dy[i];         if (nx >= 1 && nx <= n && ny >= 1 && ny <= m && tt[nx][ny] == 0 &&             !(nx == ex && ny == ey)) {           p.push(nx);           q.push(ny);           tt[nx][ny] = tt[x][y] + 1;         }       }     }   }   int main() {     scanf( %d %d , &n, &m);     getchar();     int ans = 0;     memset(tt, 0, sizeof(tt));     memset(hh, 0, sizeof(hh));     char c;     int zux, zuy;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         scanf( %c , &c);         if (c >=  0  && c <=  9 ) {           hh[i][j] = c -  0 ;         }         if (c ==  S ) {           zux = i;           zuy = j;         }         if (c ==  E ) {           tt[i][j] = 1;           ex = i;           ey = j;         }         if (c ==  T ) {           tt[i][j] = -1;         }       }       getchar();     }     p.push(ex);     q.push(ey);     bfs();     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (i == zux && j == zuy) continue;         if (i == ex && j == ey) continue;         if (tt[i][j] <= tt[zux][zuy] && tt[i][j] != 0 && tt[i][j] != -1) {           ans += hh[i][j];         }       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Node {     map<int, Node *> go;     int l, r;     Node *p, *link;     Node(int _l, int _r, Node *_p) : l(_l), r(_r), p(_p), link(0) {}   };   const int MAXN = 100 * 1000 + 5, S = 1000;   string s[MAXN];   int c[MAXN], rr[MAXN], nn, curSuf;   long long ans = 0;   vector<int> a, sid;   Node *splitEdge(Node *v, int pos) {     Node *res = new Node(v->l, pos, v->p);     v->p->go[a[v->l]] = res;     res->go[a[pos]] = v;     v->p = res;     v->l = pos;     return res;   }   pair<Node *, int> go(Node *v, int l, int len) {     while (len > 0) {       v = v->go[a[l]];       len -= v->r - v->l;       l += v->r - v->l;     }     return make_pair(v, v->r + len);   }   void add(int i, pair<Node *, int> &p) {     Node *w = 0;     while (curSuf <= i) {       Node *v = p.first;       int pos = p.second;       if (pos != v->r) {         if (a[i] == a[pos]) {           p.second++;           return;         }         v = splitEdge(v, pos);         Node *u = new Node(i, nn, v);         v->go[a[i]] = u;         if (w) w->link = v;         w = v;       } else {         if (w) w->link = v;         w = 0;         if (v->go.find(a[i]) != v->go.end()) {           p.first = v->go[a[i]];           p.second = p.first->l + 1;           return;         }         Node *u = new Node(i, nn, v);         v->go[a[i]] = u;       }       int len = 0, l = v->r;       Node *q = v;       while (!q->link && q->p) {         len += q->r - q->l;         l -= q->r - q->l;         q = q->p;       }       if (!q->p) {         if (len) p = go(q, l + 1, len - 1);       } else         p = go(q->link, l, len);       curSuf++;     }   }   Node *buildSufTree() {     nn = a.size();     Node *root = new Node(0, 0, 0);     pair<Node *, int> p = make_pair(root, 0);     curSuf = 0;     for (int i = 0; i < nn; i++) add(i, p);     return root;   }   long long dfs(Node *v, int dep = 0) {     long long res = 0;     if (v->go.empty()) res += c[sid[nn - dep]];     for (map<int, Node *>::iterator it = v->go.begin(); it != v->go.end(); it++)       res += dfs(it->second, dep + it->second->r - it->second->l);     if (v->go.empty()) {       if (a[v->l] < S) ans = max(ans, res * (rr[sid[nn - dep]] - (nn - dep)));     } else       ans = max(ans, res * dep);     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> s[i];     for (int i = 0; i < n; i++) cin >> c[i];     for (int i = 0; i < n; i++) {       for (size_t j = 0; j < s[i].length(); j++) {         a.push_back(s[i][j]);         sid.push_back(i);       }       rr[i] = a.size();       a.push_back(S + i);       sid.push_back(i);     }     dfs(buildSufTree());     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     bool flag = true;     for (int i = 0; i < n; i++) {       if (i == 0) {         int l = a[1];         int r = a[2];         if (a[i] >= l + r) flag = false;       } else if (i == n - 1) {         int l = a[n - 3];         int r = a[n - 2];         if (a[i] >= l + r) flag = false;       } else {         int l, r;         if (i + 2 > n - 1)           r = a[n - 1];         else           r = a[i + 2];         if (i - 2 < 0)           l = a[0];         else           l = a[i - 2];         if (a[i] >= l + r) flag = false;       }     }     if (flag == false)       cout <<  NO n ;     else {       cout <<  YES n ;       cout << a[0] <<    ;       int i = 1;       while (i < n) {         cout << a[i] <<    ;         i = i + 2;       }       if (n % 2)         i = n - 1;       else         i = n - 2;       while (i >= 2) {         cout << a[i] <<    ;         i = i - 2;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int c1 = 0, c2 = 0, c3 = 0;     for (int i = 0; i < n; i++) {       int x, y, z;       cin >> x >> y >> z;       c1 += x, c2 += y, c3 += z;     }     if (c1 == 0 && c2 == 0 && c3 == 0)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;      typedef long long ll;      const int Maxn = 1000005;   const int mod = 1000000007;      int fac[Maxn], inv[Maxn];   int n;   int res;      int toPower(int a, int p)   {    int res = 1;    while (p) {     if (p & 1) res = ll(res) * a % mod;     p >>= 1; a = ll(a) * a % mod;    }    return res;   }      int Inv(int x) { return toPower(x, mod - 2); }      int C(int n, int k)   {    if (n < 0 || k < 0 || k > n) return 0;    return ll(fac[n]) * inv[k] % mod * inv[n - k] % mod;   }      int main()   {    fac[0] = inv[0] = 1;    for (int i = 1; i < Maxn; i++) {     fac[i] = ll(i) * fac[i - 1] % mod;     inv[i] = Inv(fac[i]);    }    scanf( %d , &n);    for (int r = 1; r < n; r += 2)     res = (res + ll(C(r + 1, n - r - 1)) * fac[r]) % mod;    res = ll(res) * 2 % mod * n % mod;    printf( %d n , res);       return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 3e5 + 5;   vector<long long> f;   vector<long long> s;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long a, b;     cin >> a >> b;     while (a > 0) {       long long rem = a % 10;       a /= 10;       f.push_back(rem);     }     while (b > 0) {       long long rem = b % 10;       b /= 10;       s.push_back(rem);     }     reverse(f.begin(), f.end());     reverse(s.begin(), s.end());     long long dp[10];     memset(dp, 0, sizeof(dp));     for (auto x : f) {       dp[x]++;     }     if (f.size() < s.size()) {       sort(f.begin(), f.end(), greater<long long>());       for (auto x : f) {         cout << x;       }       cout << endl;       return 0;     }     bool done = 0;     for (long long i = 0; i < s.size(); ++i) {       long long x = s[i];       for (long long num = x; num >= 0; --num) {         if (dp[num] > 0) {           if (num == x) {             dp[num]--;             vector<long long> rem;             for (long long j = 0; j < 10; ++j) {               long long tmp = dp[j];               while (tmp--) {                 rem.push_back(j);               }             }             sort(rem.begin(), rem.end());             bool val = 1;             for (long long j = i + 1; j < s.size(); ++j) {               if (rem[j - (i + 1)] > s[j]) val = 0;               if (rem[j - (i + 1)] < s[j]) break;             }             if (!val) {               dp[num]++;               continue;             }             dp[num]++;           }           cout << num;           if (num < x) done = 1;           dp[num]--;           break;         }       }       if (done) break;     }     vector<long long> rem;     for (long long i = 0; i < 10; ++i) {       while (dp[i] > 0) {         rem.push_back(i);         dp[i]--;       }     }     sort(rem.begin(), rem.end(), greater<long long>());     for (auto x : rem) {       cout << x;     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   ostream& operator<<(ostream& os, vector<T> V) {     for (auto v : V) os << v <<    ;     return cout <<   ;   }   template <class T>   ostream& operator<<(ostream& os, set<T> S) {     for (auto s : S) os << s <<    ;     return cout <<   ;   }   template <class L, class R>   ostream& operator<<(ostream& os, pair<L, R> P) {     return os << P.first <<     << P.second;   }   vector<long long> vis;   vector<vector<long long>> adj;   int main() {     long long i, j, n, f1, f2, t, k, a, b, x1, x2, m, w, z;     t = 1;     while (t--) {       cin >> n >> z;       vector<pair<long long, long long>> v(n + 1);       vis.assign(n + 1, 0);       adj.assign(n + 1, {});       for (i = 1; i <= n - 1; i++) {         cin >> a >> b;         adj[a].push_back(b);         adj[b].push_back(a);       }       long long s;       queue<long long> q;       vector<long long> used(n + 1);       vector<long long> x(n + 1), y(n + 1);       vector<long long> p(n + 1);       s = z;       q.push(s);       used[s] = 1;       p[s] = -1;       while (!q.empty()) {         long long v = q.front();         q.pop();         for (long long u : adj[v]) {           if (!used[u]) {             used[u] = 1;             q.push(u);             x[u] = x[v] + 1;             p[u] = v;           }         }       }       used.assign(n + 1, 0);       s = 1;       q.push(s);       used[s] = 1;       p[s] = -1;       while (!q.empty()) {         long long v = q.front();         q.pop();         for (long long u : adj[v]) {           if (!used[u]) {             used[u] = 1;             q.push(u);             y[u] = y[v] + 1;             p[u] = v;           }         }       }       long long ans = 0;       for (i = 1; i <= n; i++) {         if (y[i] > x[i]) {           ans = max(ans, 2 * y[i]);         }       }       cout << ans;     }   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( no-stack-protector )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   #pragma GCC optimize( unroll-loops )   using namespace std;   void seriy() {     cin.tie(0);     cout.tie(0);   }   signed main() {     seriy();     long long n, m;     cin >> n >> m;     long long mn = 2e9 + 8;     for (long long i = 0; i < m; i++) {       long long l, r;       cin >> l >> r;       mn = min(mn, r - l + 1);     }     cout << mn << endl;     vector<long long> ans(n);     for (long long i = 0; i < n; i++) {       ans[i] = i % mn;     }     for (auto i : ans) cout << i <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int a = 0, b = 0;     int n, d, t;     cin >> n >> d;     int sol = 0;     for (int i = 0; i < n; ++i) {       cin >> t;       if (t == 0) {         if (b + t < 0) {           a = 0;           b = d;           sol++;         } else {           a = max(0, a);         }       } else if (a + t > d) {         sol = -1;         break;       }       a = min(d, a + t);       b = min(d, b + t);     }     cout << sol;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long t, m, n, a, u, v;   void printAnswer(vector<int> ans) {     sort(ans.begin(), ans.end());     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); i++) {       cout << ans[i] <<    ;     }     cout << endl;   }   int main() {     cin >> t;     for (int j = 0; j < t; j++) {       cin >> n >> m;       vector<vector<int> > G(n + 1);       for (int i = 0; i < m; i++) {         cin >> v >> u;         G[v].push_back(u);         G[u].push_back(v);       }       vector<int> odd;       vector<int> even;       bool seen[n + 1];       for (int i = 0; i <= n; i++) {         seen[i] = false;       }       bool oddLevel = true;       vector<int> currLevel;       currLevel.push_back(1);       seen[1] = true;       while (currLevel.size() > 0) {         if (oddLevel) {           odd.insert(odd.end(), currLevel.begin(), currLevel.end());         } else {           even.insert(even.end(), currLevel.begin(), currLevel.end());         }         vector<int> nextLevel;         for (int i = 0; i < currLevel.size(); i++) {           int n = currLevel[i];           for (int k = 0; k < G[n].size(); k++) {             if (!seen[G[n][k]]) {               seen[G[n][k]] = true;               nextLevel.push_back(G[n][k]);             }           }         }         currLevel = nextLevel;         oddLevel = !oddLevel;       }       if (odd.size() >= even.size()) {         printAnswer(even);       } else {         printAnswer(odd);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int len, a, b, c;   string s;   int main() {     cin >> s;     len = s.length();     for (int i = 0; i < len; i++) {       if (s[i] ==  a )         a++, c++;       else         b++;       a = max(a, b);       b = max(b, c);     }     cout << a;     return 0;   }