malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int a[300001];   const long long mod = 1000000007;   int main(int argc, const char* argv[]) {     string S;     cin >> S;     int n = (int)S.size();     string A(n,  2 );     int scr = 0;     for (int i = 0; i < n; ++i) {       char a = S[(i + n - 1) % n];       char b = S[i];       char c = S[(i + 1) % n];       if (a == b && b == c)         A[i] =  0 ;       else if (a == b && b != c) {         ++scr;         A[i] =  1 ;         A[(i + 1) % n] =  0 ;       } else if (a != b && b == c)         A[i] =  0 ;     }     int fst = 0;     while (fst < n && !(A[fst] !=  2  && A[(fst + 1) % n] ==  2 )) ++fst;     if (fst == n) {       if (A[0] ==  2 )         cout << n / 2 << endl;       else         cout << scr << endl;       return 0;     }     int j = 0;     for (int i = 0; i < n; ++i) {       char a = A[(i + fst) % n];       char b = A[(i + fst + 1) % n];       if (a ==  2  && b !=  2 ) {         scr += (i - j + 1) / 2;       }       if (a !=  2  && b ==  2 ) j = i;     }     cout << scr << endl;   }
#include <bits/stdc++.h>   using namespace std;   string s;   int main() {     int n, a, b, k;     scanf( %d%d%d%d , &n, &a, &b, &k);     int tot = 0;     cin >> s;     int prev = -1;     for (int i = 0; i < n; i++)       if (s[i] ==  1 ) {         tot += (i - prev - 1) / b;         prev = i;       }     tot += (n - prev - 1) / b;     int ans = tot - a + 1;     printf( %d n , ans);     int cnt = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  1 ) {         cnt = 0;       } else {         cnt++;       }       if (cnt == b && ans) {         ans--;         printf( %d  , i + 1);         cnt = 0;       }     }     printf(  n );     return 0;   }
#include<bits/stdc++.h>   using namespace std;   typedef long long ll;   typedef unsigned long long ull;   const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   const int inf = 0x3f3f3f3f;   const ll linf = 0x3f3f3f3f3f3f3f3f;   const ll mod = 1e9 + 7;   //const ll mod = 998244353;       ll ksm(ll x,ll k) {    ll ret=1;    while(k) {     if(k&1) ret=ret*x%mod;     x=x*x%mod,k>>=1;    }    return ret;   }       ll prime[10000005],pcnt,phi[10000005];   bool mark[10000005];   inline void pre(ll n) {    mark[1]=1;    for(ll i=2;i<=n;i++) {     if(!mark[i]) prime[++pcnt]=i/*,phi[i]=i-1*/;     for(ll j=1;j<=pcnt;j++) {      ll k=i*prime[j];      if(k>n) break;      mark[k]=1;      if(i%prime[j]==0) {   //    phi[k]=phi[i]*prime[j];       break;      }   //   else phi[k]=phi[i]*(prime[j]-1);     }    }   }      struct data {    int u,v,val;    data(int _u=0,int _v=0,int _val=0):u(_u),v(_v),val(_val) {}    bool operator < (const data &x) const {     if(val==x.val) return u<x.u;     return val<x.val;    }   }a[505*505];   int fa[505*505],c[505*505];   vector <int> u,v;      int getfa(int x) {    return x==fa[x] ? x:fa[x]=getfa(fa[x]);   }      int main() {    ios::sync_with_stdio(false);    cin.tie(nullptr);    int T=1;   // cin>>T;    while(T--) {     int n; cin>>n;     for(int i=1;i<=n*n;i++) fa[i]=i;     int cnt=0;     for(int i=1;i<=n;i++) {      for(int j=1;j<=n;j++) {       int x; cin>>x;       if(i==j) c[i]=x;       if(i>=j) continue;       a[++cnt]=data(i,j,x);      }     }     sort(a+1,a+cnt+1);     int k=n;     for(int i=1;i<=cnt;i++) {      int fu=getfa(a[i].u),fv=getfa(a[i].v);      if(fu==fv) continue;      if(fu>n && c[fu]==a[i].val) {       fa[fv]=fu,u.push_back(fv),v.push_back(fu);       continue;      }      if(fv>n && c[fv]==a[i].val) {       fa[fu]=fv,u.push_back(fu),v.push_back(fv);       continue;      }      k++;      fa[fu]=fa[fv]=k;      c[k]=a[i].val;      u.push_back(fu),v.push_back(k);      u.push_back(fv),v.push_back(k);     }     cout<<k<<  n ;     for(int i=1;i<=k;i++) cout<<c[i]<<   ;     cout<<  n ;     cout<<k<<  n ;     for(int i=0;i<u.size();i++) cout<<u[i]<<   <<v[i]<<  n ;    }   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b);   bool prime(int n);   long long sumdigit(long long n);   bool ispowerof2(int n);   long long onesinbinary(long long n);   long long power(long long a, long long b);   bool cmp(pair<int, int> x, pair<int, int> y) { return x.second < y.second; }   bool cmp(int x, int y) { return x > y; }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long t;     cin >> t;     while (t--) {       int n;       cin >> n;       char arr[2][n];       for (int i = 0; i < 2; i++) {         for (int j = 0; j < n; j++) {           cin >> arr[i][j];         }       }       int ans = 0;       vector<int> v;       for (int i = 0; i < n; i++) {         if (arr[0][i] ==  0  && arr[1][i] ==  0 )           ans++;         else if (arr[0][i] ==  0  || arr[1][i] ==  0 )           ans += 2;         else {           v.push_back(i);         }       }       int x = v.size();       for (int i = 0; i < x; i++) {         if (v[i] < n - 1 && v[i] > 0) {           if (arr[0][v[i] - 1] ==  0  && arr[1][v[i] - 1] ==  0 ) {             ans++;           } else if (arr[0][v[i] + 1] ==  0  && arr[1][v[i] + 1] ==  0 ) {             ans++;             arr[0][v[i] + 1] =  1 , arr[1][v[i] + 1] =  1 ;           }         } else if (v[i] == n - 1) {           if (arr[0][v[i] - 1] ==  0  && arr[1][v[i] - 1] ==  0 ) {             ans++;           }         } else if (v[i] == 0) {           if (arr[0][v[i] + 1] ==  0  && arr[1][v[i] + 1] ==  0 ) {             ans++;             arr[0][v[i] + 1] =  1 , arr[1][v[i] + 1] =  1 ;           }         }       }       cout << ans << endl;     }     return 0;   }   long long onesinbinary(long long n) {     long long cnt = 0;     while (n) {       n = n & (n - 1);       cnt++;     }     return cnt;   }   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   bool prime(int n) {     for (int i = 2; i * i <= n; i++)       if (n % i == 0) return false;     return true;   }   long long sumdigit(long long n) {     int c = 0;     while (n > 0) {       c += n % 10;       n /= 10;     }     return c;   }   bool ispowerof2(int n) {     if (n == 0) return false;     return (!(n & ((n) & (n - 1))));   }   long long power(long long a, long long b) {     if (b == 0) return 1;     long long res = 1;     while (b) {       if (b % 2 == 1) res = (res * a) % 1000000007;       a = (a * a) % 1000000007;       b /= 2;     }     return res;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int p, c = 0;     cin >> p;     long long int x = p;     long long int n = std::numeric_limits<int>::digits - 1;     std::string s;     s.reserve(n + 1);     do s.push_back(((x >> n) & 1) +  0 );     while (--n > -1);     for (auto x : s)       if (x ==  1 ) c++;     cout << c;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Str {     int l;     char *s;   } str[50010 << 2];   int tot;   char s[3100000];   int k;   int n, l[50010], r[50010];   char ans[3100000];   int cut(int pos) {     for (int i = 0; i < tot; i++)       if (pos == 0) {         tot++;         for (int k = tot - 1; k > i; k--) str[k] = str[k - 1];         return i;       } else if (str[i].l <= pos)         pos -= str[i].l;       else {         tot += 2;         for (int k = tot - 1; k > i + 1; k--) str[k] = str[k - 2];         str[i + 2].l = str[i].l - pos;         str[i + 2].s = str[i].s + pos;         str[i].l = pos;         return i + 1;       }     return tot++;   }   void getans(int h, int t) {     int l = 0;     for (int i = 0; t >= 0 && i < tot; i++)       if (str[i].l <= h) {         h -= str[i].l;         t -= str[i].l;       } else {         for (int k = max(0, h); k < str[i].l && k <= t; k++)           ans[l++] = str[i].s[k];         int tmp = min(str[i].l, t);         h -= tmp;         t -= tmp;       }   }   void deal(int d, int len) {     if (d < 0) {       Str tmp;       tmp.l = len;       tmp.s = s + 1;       str[tot++] = tmp;       return;     }     if (r[d] >= len) {       deal(d - 1, len);       return;     }     int c = r[d] - l[d] + 1;     if (r[d] + c >= len) {       deal(d - 1, r[d]);       Str tmp;       tmp.l = len - r[d];       tmp.s = new char[len - r[d]];       int c_2 = c / 2;       int D = (tmp.l >= c_2) ? c : (tmp.l * 2);       getans(l[d], l[d] + D - 1);       for (int i = 0; i < tmp.l; i++)         if (i < c_2)           tmp.s[i] = ans[i * 2 + 1];         else           tmp.s[i] = ans[(i - c_2) << 1];       str[tot++] = tmp;     } else {       deal(d - 1, len - c);       int pos = cut(r[d] + 1);       Str tmp;       tmp.l = c;       tmp.s = new char[c];       int c_2 = c / 2;       getans(l[d], r[d]);       for (int i = 0; i < c; i++)         if (i < c_2)           tmp.s[i] = ans[i * 2 + 1];         else           tmp.s[i] = ans[(i - c_2) << 1];       str[pos] = tmp;     }   }   int main() {     scanf( %s , s + 1);     scanf( %d , &k);     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d%d , &l[i], &r[i]);     tot = 1;     str[0].l = 1;     str[0].s = new char[1];     str[0].s[0] =    ;     deal(n - 1, k);     getans(0, k);     ans[k + 1] = 0;     printf( %s n , ans + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long L[100005], R[100005], odd[100005], s[100005], dp[100005], ans = 0;   int n;   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) scanf( %I64d , &s[i]);     L[0] = 0;     for (int i = 1; i < n; i++) {       if (s[i] == 1)         L[i] = 0;       else         L[i] = L[i - 1] + s[i] / 2 * 2;     }     R[n - 1] = 0;     for (int i = n - 2; i >= 0; i--) {       if (s[i + 1] == 1)         R[i] = 0;       else         R[i] = R[i + 1] + s[i + 1] / 2 * 2;     }     dp[0] = 0;     for (int i = 1; i < n; i++) {       dp[i] = max(dp[i - 1] + (s[i] - 1) / 2 * 2 + 1, L[i]);     }     for (int i = 0; i < n; i++) {       ans = max(ans, dp[i] + R[i]);     }     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     while (cin >> n) {       long long i = 5, cnt = 1, x, ans = 0, y, z = 5, m;       if (n < 5 || n == 5) {         if (n == 1)           cout <<  Sheldon  << endl;         else if (n == 2)           cout <<  Leonard  << endl;         else if (n == 3)           cout <<  Penny  << endl;         else if (n == 4)           cout <<  Rajesh  << endl;         else if (n == 5)           cout <<  Howard  << endl;         continue;       }       while (i < n || i == n) {         x = i;         if (i == n) {           x = 0;           break;         } else {           z += z;           i += z;         }         cnt = cnt * 2;       }       if (x == 0)         cout <<  Howard  << endl;       else {         y = n - x;         if (y < 1) y *= -1;         ans = y / cnt;         ans++;         if (y % cnt == 0) ans--;         if (ans == 1)           cout <<  Sheldon  << endl;         else if (ans == 2)           cout <<  Leonard  << endl;         else if (ans == 3)           cout <<  Penny  << endl;         else if (ans == 4)           cout <<  Rajesh  << endl;         else if (ans == 5)           cout <<  Howard  << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int modd = 998244353;   const int maxn = 2000 + 10;   int n, k;   long long dp[maxn][maxn][4];   void solve() {     dp[1][1][0] = dp[1][1][3] = 1;     dp[1][2][1] = dp[1][2][2] = 1;     for (int i = 2; i <= n; i++) {       dp[i][1][0] = dp[i][1][3] = 1;       dp[i][1][1] = dp[i][1][2] = 0;       for (int j = 2; j <= k; j++) {         dp[i][j][0] = (dp[i - 1][j][0] % modd + dp[i - 1][j][1] % modd +                        dp[i - 1][j][2] % modd + dp[i - 1][j - 1][3] % modd) %                       modd;         dp[i][j][1] = (dp[i - 1][j - 1][0] % modd + dp[i - 1][j][1] % modd +                        dp[i - 1][j - 2][2] % modd + dp[i - 1][j - 1][3] % modd) %                       modd;         dp[i][j][2] = (dp[i - 1][j - 1][0] % modd + dp[i - 1][j - 2][1] % modd +                        dp[i - 1][j][2] % modd + dp[i - 1][j - 1][3] % modd) %                       modd;         dp[i][j][3] = (dp[i - 1][j - 1][0] % modd + dp[i - 1][j][1] % modd +                        dp[i - 1][j][2] % modd + dp[i - 1][j][3] % modd) %                       modd;       }     }   }   int main() {     cin >> n >> k;     solve();     cout << (dp[n][k][0] % modd + dp[n][k][1] % modd + dp[n][k][2] % modd +              dp[n][k][3] % modd) %                 modd          << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 300010;   int ans[N], vis[N];   vector<int> G[N], s[N], tmp;   void dfs(int u, int fa) {     int sz = s[u].size();     for (int i = 1; i <= sz; i++) vis[i] = 0;     for (int j : s[u]) {       if (ans[j] && ans[j] <= sz) vis[ans[j]] = 1;     }     for (int j = 1; j <= sz; j++) {       if (!vis[j]) tmp.push_back(j);     }     int cur = 0;     for (int j : s[u]) {       if (!ans[j]) ans[j] = tmp[cur++];     }     tmp.clear();     for (int v : G[u]) {       if (v == fa) continue;       dfs(v, u);     }   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       int cnt;       scanf( %d , &cnt);       for (int j = 1; j <= cnt; j++) {         int x;         scanf( %d , &x);         s[i].push_back(x);       }     }     for (int i = 1; i <= n - 1; i++) {       int u, v;       scanf( %d%d , &u, &v);       G[u].push_back(v);       G[v].push_back(u);     }     dfs(1, 0);     int mx = 0;     for (int i = 1; i <= m; i++) {       if (!ans[i]) ans[i] = 1;       mx = max(mx, ans[i]);     }     printf( %d n , mx);     for (int i = 1; i <= m; i++) printf( %d  , ans[i]);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     while (cin >> n) {       if (n == 1 || n == 2)         cout <<  -1 n ;       else if (n == 3)         cout <<  210 n ;       else {         if (n % 6 == 1) {           cout <<  1 ;           for (int i = 3; i < n; i++) cout <<  0 ;           cout <<  20 n ;         }         if (n % 6 == 2) {           cout <<  1 ;           for (int i = 3; i < n - 1; i++) cout <<  0 ;           cout <<  200 n ;         }         if (n % 6 == 3) {           cout <<  1 ;           for (int i = 3; i < n - 1; i++) cout <<  0 ;           cout <<  110 n ;         }         if (n % 6 == 4) {           cout <<  1 ;           for (int i = 3; i < n; i++) cout <<  0 ;           cout <<  50 n ;         }         if (n % 6 == 5) {           cout <<  1 ;           for (int i = 3; i < n; i++) cout <<  0 ;           cout <<  80 n ;         }         if (n % 6 == 0) {           cout <<  1 ;           for (int i = 3; i < n - 1; i++) cout <<  0 ;           cout <<  170 n ;         }       }     }     return 0;   }
#include<bits/stdc++.h>   using namespace std;   bool ok[100005];   typedef long long int ll;   int gcd(int a ,int b)   {       if(b==0)       return a;       else if(a==0)       return a;       else           return gcd(b,a%b);   }   int main()   {       int n;       cin>>n;       ll prod=1;       for(int i=1;i<n;i++)       {           if(gcd(n,i)==1)           {               ok[i]=1;               prod=(prod*i)%n;           }       }       if(prod!=1)       ok[prod]=0;          cout<<count(ok+1,ok+n,1)<<endl;       for(int i=1;i<n;i++)       {           if(ok[i])           cout<<i<<   ;       }       return 0;      }
#include <bits/stdc++.h>   using namespace std;   int inf = 1000000000, mxx, mxy, mnx = inf, mny = inf, n, m, i, j, r = 0,       x[2000001], y[2000001];   char a[3001][3001], c[3001][3001];   bool ok(int mxx, int mxy, int mnx, int mny) {     for (int i = 0; i < r; i++)       if (x[i] < mnx || x[i] > mxx || y[i] < mny || y[i] > mxy ||           (x[i] != mxx && x[i] != mnx && y[i] != mxy && y[i] != mny))         return false;     return (mxx - mnx == mxy - mny && mxx < n && mxy < m && mnx >= 0 && mny >= 0);   }   void go(int mxx, int mxy, int mnx, int mny) {     int i, j;     for (i = 0; i < n; i++)       for (j = 0; j < m; j++) {         if (i >= mnx && i <= mxx && j >= mny && j <= mxy &&             ((i == mxx || i == mnx) || (j == mxy || j == mny)) && a[i][j] !=  w )           c[i][j] =  + ;         else           c[i][j] = a[i][j];       }   }   int main() {     cin >> n >> m;     for (i = 0; i < n; i++)       for (j = 0; j < m; j++) {         cin >> a[i][j];         if (a[i][j] ==  w ) {           x[r] = i;           y[r] = j;           r++;         }       }     for (i = 0; i < r; i++) {       if (x[i] > mxx) mxx = x[i];       if (y[i] > mxy) mxy = y[i];       if (x[i] < mnx) mnx = x[i];       if (y[i] < mny) mny = y[i];     }     for (i = 0; i <= m; i++) {       if (ok(mxx, i + (mxx - mnx), mnx, i)) {         go(mxx, i + (mxx - mnx), mnx, i);         for (i = 0; i < n; i++)           for (j = 0; j < m; j++) {             cout << c[i][j];             if (j == m - 1) cout << endl;           }         return 0;       }     }     for (i = 0; i <= n; i++) {       if (ok(i + (mxy - mny), mxy, i, mny)) {         go(i + (mxy - mny), mxy, i, mny);         for (i = 0; i < n; i++)           for (j = 0; j < m; j++) {             cout << c[i][j];             if (j == m - 1) cout << endl;           }         return 0;       }     }     cout <<  -1 ;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 11, MAXL = 100000 + 10;   struct State {     int len, fa, num[MAXN], tr[26];     State() : len(0), fa(0) {       memset(num, 0, sizeof(num));       memset(tr, 0, sizeof(tr));     }     State(int len, int fa, int numr, int ref) : len(len), fa(fa) {       memset(num, 0, sizeof(num));       memset(tr, 0, sizeof(tr));       num[ref] = numr;     }   } SAM[MAXL * 2];   int n, tot = 1, c[MAXN][2];   string str[MAXN];   void Construct_SAM(const string &str, int ref) {     int ns = str.size();     for (int cp = 1, pre = 1, i = 0, id = str[i] -  a ; i < ns;          id = str[++i] -  a , pre = cp) {       if (SAM[cp].tr[id] && SAM[SAM[cp].tr[id]].len == SAM[cp].len + 1) {         cp = SAM[cp].tr[id];         ++SAM[cp].num[ref];         continue;       }       cp = ++tot;       SAM[cp] = State(SAM[pre].len + 1, 0, 1, ref);       for (; pre && !SAM[pre].tr[id]; SAM[pre].tr[id] = cp, pre = SAM[pre].fa)         ;       if (pre != 0)         if (SAM[pre].len + 1 == SAM[SAM[pre].tr[id]].len)           SAM[cp].fa = SAM[pre].tr[id];         else {           int tp = SAM[pre].tr[id];           SAM[++tot] = State(SAM[pre].len + 1, SAM[tp].fa, 0, 0);           memcpy(SAM[tot].tr, SAM[tp].tr, sizeof(SAM[tp].tr));           SAM[cp].fa = SAM[tp].fa = tot;           for (; pre && SAM[pre].tr[id] == tp;                SAM[pre].tr[id] = tot, pre = SAM[pre].fa)             ;         }       else         SAM[cp].fa = 1;     }   }   void init() {     cin >> str[0];     c[0][0] = 1, c[0][1] = MAXL;     Construct_SAM(str[0], 0);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> str[i] >> c[i][0] >> c[i][1];       Construct_SAM(str[i], i);     }   }   vector<int> l[MAXL];   void Calc(int id) {     for (int i = MAXL - 1; i >= 0; --i)       for (int j = 0; j < (int)l[i].size(); ++j)         SAM[SAM[l[i][j]].fa].num[id] += SAM[l[i][j]].num[id];   }   bool Check(int x) {     for (int i = 0; i <= n; ++i)       if (!(SAM[x].num[i] >= c[i][0] && SAM[x].num[i] <= c[i][1])) return false;     return true;   }   void solve() {     for (int i = 1; i <= tot; ++i) l[SAM[i].len].push_back(i);     for (int i = 0; i <= n; ++i) Calc(i);     long long CC = 0;     for (int i = 2; i <= tot; ++i)       if (Check(i)) CC += SAM[i].len - SAM[SAM[i].fa].len;     cout << CC << endl;   }   int main() {     init();     solve();     fclose(stdin);     fclose(stdout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   set<long long int> st;   set<long long int>::iterator it;   long long int cnt[200010];   int main() {     long long int n, a, b, x, y, z, p, m, d, mn, mx, t, i;     scanf( %lld , &t);     while (t--) {       scanf( %lld , &n);       p = 0;       for (i = 1; i <= n; i++) {         scanf( %lld , &a);         st.insert(a);         cnt[a]++;         p = max(p, cnt[a]);       }       x = st.size();       if (x == 1) {         if (p >= 2) {           cout << 1 << endl;         } else           cout << 0 << endl;       } else {         x = x - 1;         if (p <= x)           cout << p << endl;         else {           d = p - x;           if (d > 1)             cout << x + 1 << endl;           else             cout << x << endl;         }       }       for (i = 1; i <= n; i++) cnt[i] = 0;       st.clear();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool prime[1500000 + 10];   bool a[1500000 + 10];   int func(int N, int x) {     int i, ans = 0;     if (x == 2) return 0;     if (a[1]) return 1;     if (x >= 1500000) return -1;     for (i = 2; i <= x - 1; i++)       if (prime[i])         if (a[i])           ans++;         else           return -1;     return ans;   }   int main(void) {     int i, j, N, x, tmp;     for (i = 2; i < 1500000; i++) prime[i] = true;     for (i = 2; i * i < 1500000; i++)       if (prime[i])         for (j = i * i; j < 1500000; j += i) prime[j] = false;     scanf( %d%d , &N, &x);     for ((i) = 0; (i) < (int)(N); (i)++) {       scanf( %d , &tmp);       if (tmp < 1500000) a[tmp] = true;     }     int ans = func(N, x);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void task();   int main() {     srand(time(0));     ios_base::sync_with_stdio(0);     task();     return 0;   }   vector<int> prefix_function(string s) {     int n = s.length();     vector<int> p(n, 0);     for (int i = 1; i < n; ++i) {       int j = p[i - 1];       while (j > 0 && s[i] != s[j]) j = p[j - 1];       if (s[i] == s[j]) p[i] = j + 1;     }     return p;   }   string s[3];   void task() {     cin >> s[0] >> s[1] >> s[2];     sort(s, s + 3);     int ans = 1e9 + 10;     do {       string ss = s[0];       {         vector<int> p = prefix_function(s[1] +  !  + s[0]);         int mx = 0;         for (int i = s[1].length(); i < ((int)((p).size())); ++i)           mx = max(mx, p[i]);         if (p.back() != ((int)((s[1]).size())) && mx != ((int)((s[1]).size())))           ss += s[1].substr(p.back(), ((int)((s[1]).size())) - p.back());       }       {         vector<int> p = prefix_function(s[2] +  !  + ss);         int mx = 0;         for (int i = s[2].length(); i < ((int)((p).size())); ++i)           mx = max(mx, p[i]);         if (p.back() != ((int)((s[2]).size())) && mx != ((int)((s[2]).size())))           ss += s[2].substr(p.back(), ((int)((s[2]).size())) - p.back());         ans = min(ans, ((int)((ss).size())));       }     } while (next_permutation(s, s + 3));     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int MOD = 1e9 + 7;   const int maxn = 3e5 + 10;   const int maxv = 1e3 + 10;   const double eps = 1e-9;   std::vector<int> G[maxn];   int ans[maxn];   void inv(int i) { ans[i] ^= 1; }   bool bad(int u) {     int cnt = 0;     for (int i = 0; i < G[u].size(); i++) {       cnt += ans[u] == ans[G[u][i]];     }     return cnt >= 2;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       int u, v;       scanf( %d%d , &u, &v);       if (u > v) swap(u, v);       G[v].push_back(u);       G[u].push_back(v);     }     stack<int> s;     for (int i = 1; i <= n; i++) {       if (bad(i)) s.push(i);     }     while (s.size()) {       int u = s.top();       s.pop();       if (bad(u)) inv(u);       for (int i = 0; i < G[u].size(); i++) {         int v = G[u][i];         if (bad(G[u][i])) s.push(v);       }     }     for (int i = 1; i <= n; i++) {       printf( %d , ans[i]);     }     puts(  );     return 0;   }