malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int oo = (int)1e9;   const double PI = 2 * acos(0.0);   const double eps = 1e-7;   int dx[] = {1, -1, 0, 0};   int dy[] = {0, 0, 1, -1};   int main() {     int n, m;     cin >> n >> m;     string s;     int mx = 0;     int c = 0;     for (int i = 0; i < m; i++) {       cin >> s;       int va = 0;       for (int l = 0; l < ((int)((s).size())); l++)         if (s[l] ==  0 ) {           c++;           va = 1;           break;         }       if (va == 0) {         mx = max(mx, c);         c = 0;       }     }     cout << max(mx, c) << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const long long inf = 1LL << 62;   const long long mx = 100005;   const double eps = 1e-10;   long long dx[10] = {1, 0, -1, 0};   long long dy[10] = {0, -1, 0, 1};   long long power(long long a, long long b) {     if (b == 0) return 1;     long long x = power(a, b / 2);     x = x * x;     if (b % 2) x = x * a;     return x;   }   long long Set(long long N, long long pos) { return N = N | (1LL << pos); }   long long reset(long long N, long long pos) { return N = N & ~(1LL << pos); }   bool check(long long N, long long pos) { return (bool)(N & (1LL << pos)); }   string str, ss;   set<string> s;   int main() {     long long tst, a, b, c, k, n, m, res = 0, ans = 0, t = 0;     cin >> str;     n = (long long)(str).size();     for (char ch =  a ; ch <=  z ; ch++) {       ss.clear();       ss.push_back(ch);       ss += str;       s.insert(ss);     }     long long i, j;     for (i = 0; i < n; i++) {       ss.clear();       for (j = 0; j <= i; j++) {         ss.push_back(str[j]);       }       string first = ss;       for (char ch =  a ; ch <=  z ; ch++) {         ss = first;         ss.push_back(ch);         for (j = i + 1; j < n; j++) {           ss.push_back(str[j]);         }         s.insert(ss);       }     }     cout << (long long)(s).size() <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int M, K, i, st, ed, ans[2], arr[100005];   int main() {     cin >> M >> K;     for (i = st = ed = 0; i < M; i++) cin >> arr[i];     sort(arr, arr + M, greater<int>());     while (1) {       while ((ed + 1) < M && (arr[st] - arr[ed + 1]) <= K)         K -= (arr[st] - arr[++ed]);       if ((ed - st + 1) >= ans[0]) {         ans[0] = (ed - st + 1);         ans[1] = arr[st];       }       if (ed == M - 1 || st == M - 1) break;       K += ((arr[st] - arr[st + 1]) * (ed - st));       st++;     }     cout << ans[0] <<     << ans[1] << endl;   }
#include <bits/stdc++.h>   long long ar[1000010], fact[1000010];   long long expo(long long x, long long n) {     long long res = 1;     while (n) {       if (n & 1LL) res = (res * x) % 1000000007;       x = (x * x) % 1000000007;       n >>= 1LL;     }     return (res % 1000000007);   }   long long binomial(int n, int k) {     long long x = fact[n];     long long y = (fact[k] * fact[n - k]) % 1000000007;     long long res = (x * expo(y, 1000000007 - 2)) % 1000000007;     return res;   }   long long solve(int n, long long ar[1000010]) {     if (n == 1) return ar[0] % 1000000007;     int i, j, k;     long long x, y, z, res = 0;     if ((n % 4) == 0) {       for (i = 0; i < n; i++) {         x = binomial(n / 2 - 1, i / 2) * ar[i] % 1000000007;         if (i % 2 == 1)           res = (res - x + 1000000007) % 1000000007;         else           res = (res + x) % 1000000007;       }     }     if ((n % 4) == 1) {       for (i = 0; i < n; i++) {         if (i % 2 == 0) res = (res + binomial(n / 2, i / 2) * ar[i]) % 1000000007;       }     }     if ((n % 4) == 2) {       for (i = 0; i < n; i++) {         res = (res + binomial(n / 2 - 1, i / 2) * ar[i]) % 1000000007;       }     }     if ((n % 4) == 3) {       for (i = 0; i < n; i++) {         if ((i % 2) == 1) {           x = binomial(n / 2 - 1, i / 2) * 2 % 1000000007;         } else {           x = binomial(n / 2 - 1, i / 2);           if (i)             x = (x - binomial(n / 2 - 1, i / 2 - 1) + 1000000007) % 1000000007;           if ((2 * i) > n) x = x - 1000000007;         }         res = (res + ((x * ar[i]) % 1000000007) + 1000000007) % 1000000007;       }     }     return res % 1000000007;   }   int main() {     int n, i, j, k;     for (i = 1, fact[0] = 1; i < 1000010; i++)       fact[i] = (fact[i - 1] * i) % 1000000007;     while (scanf( %d , &n) != EOF) {       for (i = 0; i < n; i++) scanf( %lld , &ar[i]);       printf( %lld n , solve(n, ar));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, q;   const long long MXN = 200005;   long long arr[MXN];   long long seg[MXN * 4];   void build(long long ind, long long l, long long r) {     if (l == r) {       seg[ind] = arr[l];       return;     }     long long m = (l + r) / 2;     build(ind << 1, l, m);     build((ind << 1) | 1, m + 1, r);     seg[ind] = seg[ind * 2] + seg[ind * 2 + 1];   }   void upd(long long ind, long long l, long long r, long long pos, long long to) {     if (l == r) {       seg[ind] = to;       return;     }     long long m = (l + r) / 2;     if (pos <= m)       upd(ind << 1, l, m, pos, to);     else       upd((ind << 1) | 1, m + 1, r, pos, to);     seg[ind] = seg[ind * 2] + seg[ind * 2 + 1];   }   long long qry(long long ind, long long l, long long r, long long ql,                 long long qr) {     if (ql <= l && r <= qr) {       return seg[ind];     }     if (ql > r || qr < l) {       return 0;     }     long long m = (l + r) / 2;     return qry(ind << 1, l, m, ql, qr) + qry((ind << 1) | 1, m + 1, r, ql, qr);   }   long long fact[MXN];   set<long long> rm;   long long T(long long dv) {     auto x = rm.begin();     for (long long j = 0; j < dv; j++) x++;     return *x;   }   vector<long long> wh;   void sep(long long kth) {     for (long long i = 1; i <= n; i++) {       rm.insert(i);     }     for (long long pl = n - 1; pl >= 0; pl--) {       long long dv = kth / fact[pl];       kth %= fact[pl];       long long K = T(dv);       wh.push_back(K);       rm.erase(K);     }     for (long long i = 1; i <= n; i++) {       arr[i] = wh[i - 1];     }     wh.clear();   }   long long SP = 0;   void rew(long long kth) {     if (SP == kth) return;     if (n <= 15) {       sep(kth);     } else {       for (long long i = 1; i <= 15; i++) {         rm.insert(i);       }       for (long long pl = 15 - 1; pl >= 0; pl--) {         long long dv = kth / fact[pl];         kth %= fact[pl];         long long K = T(dv);         wh.push_back(K);         rm.erase(K);       }       for (long long i = 1; i <= 15; i++) {         arr[n - 15 + i] = n - 15 + wh[i - 1];       }       wh.clear();     }     SP = kth;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     fact[0] = 1;     cin >> n >> q;     for (long long i = 1; i <= n; i++) arr[i] = i;     for (long long i = 1; i <= 20; i++) {       fact[i] = fact[i - 1] * i;     }     long long k = 0;     build(1, 1, n);     for (long long i = 0; i < q; i++) {       long long t;       cin >> t;       if (t == 1) {         rew(k);         for (long long i = max(1ll, n - 20); i <= n; i++) {           upd(1, 1, n, i, arr[i]);         }         long long l, r;         cin >> l >> r;         cout << qry(1, 1, n, l, r) <<   n ;       } else {         long long w;         cin >> w;         k += w;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   int main() {     int n;     scanf( %d , &n);     vector<long long> a(n);     for (int i = 0; i < n; i++) {       scanf( %lld , &a[i]);     }     vector<long long> t(n);     for (int i = 0; i < n; i++) {       scanf( %lld , &t[i]);     }     multiset<long long> S;     long long sum = 0;     for (int i = 0; i < n; i++) {       S.insert(a[i] + sum);       long long ans = 0;       sum += t[i];       while (!S.empty()) {         long long top = *S.begin();         if (top < sum) {           ans += top - (sum - t[i]);           S.erase(S.begin());         } else {           break;         }       }       ans += (long long)(int)((S).size()) * t[i];       printf( %lld  , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   long long ori[100005];   int main() {     scanf( %d , &n);     int i = 1;     for (i; i <= n; i++) {       scanf( %I64d , &ori[i]);     }     sort(ori + 1, ori + n + 1);     i = 1;     int ss = n - 2;     bool flag = false;     for (i; i <= ss; i++) {       int j = i + 1;       int k = j + 1;       if (ori[i] + ori[j] > ori[k]) {         flag = true;         break;       }     }     if (flag) {       printf( YES );     } else {       printf( NO );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     vector<pair<int, int>> a(n);     vector<int> b(n);     vector<int> c(n);     for (int i = 0; i < n; i++) {       int x;       cin >> x;       a[i] = {x, i};     }     while (k--) {       int x, y;       cin >> x >> y;       x--;       y--;       if (a[x].first > a[y].first) b[x]++;       if (a[x].first < a[y].first) b[y]++;     }     sort(a.begin(), a.end());     int l = 0;     for (int i = 0; i < n; i++) {       k = i;       k -= l;       k -= b[a[i].second];       c[a[i].second] = k;       if (i < n - 1) {         if (a[i].first < a[i + 1].first)           l = 0;         else           l++;       }     }     for (auto it : c) cout << it <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 300500;   struct node {     long long x;     int id;     node() {}     bool operator<(const node ot) const {       if (x != ot.x) return x < ot.x;       return id < ot.id;     }   } a[maxn];   long long x[maxn];   long long su[maxn];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < (int)(n); ++i) {       scanf( %lld , &x[i]);       a[i].x = x[i] + 1e9;       a[i].id = i + 1;     }     int k;     scanf( %d , &k);     sort(a, a + n);     long long dif = 1e18, ans = 0;     long long cur = 0;     for (int i = 0; i < (int)(n); ++i) su[i + 1] = su[i] + a[i].x;     for (int i = 0; i < (int)(k); ++i) cur += a[i].x * i - (su[i]);     dif = cur;     for (int i = k; i < n; i++) {       int j = i - k;       cur -= (su[i] - su[j + 1]) - a[j].x * (k - 1);       cur += a[i].x * (k - 1) - (su[i] - su[j + 1]);       if (cur < dif) {         ans = i - k + 1;         dif = cur;       }     }     for (int i = 0; i < (int)(k); ++i) printf( %d  , a[ans + i].id);   }
#include <bits/stdc++.h>   using namespace std;   long double f[1011][1011];   int m, n;   void init() {     memset(f, 0, sizeof f);     f[1][1] = 1;     for (int i = (1), _b = (n - 1); i <= _b; i++) {       for (int x = (0), _b = (min(i, m)); x <= _b; x++)         if (f[i][x] > 1e-50) {           f[i + 1][x] += f[i][x] * ((m * n - m) - (i - x)) / (double)(m * n - i);           f[i + 1][x + 1] += f[i][x] * (m - x) / (double)(m * n - i);         }     }   }   int main() {     ios ::sync_with_stdio(false);     cout << (fixed) << setprecision(8);     while (cin >> n >> m) {       init();       double res = 0.0;       for (int k = (1), _b = (min(m, n)); k <= _b; k++) {         res += f[n][k] * k / (double)n;       }       cout << res << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e5 + 10;   long long int vis[N];   vector<vector<int> > v;   int dfs(int t) {     vis[t] = 1;     for (int i = 0; i < v[t].size(); i++) {       if (vis[v[t][t]] == 0) {         dfs(v[t][i]);       }     }     return 0;   }   int main() {     long long int n, k;     cin >> n >> k;     long long int y = 1;     long long int i = 0;     long long int ans = 0, p = 0, d = 1;     while (1) {       if (d > n) {         break;       }       p++;       d = pow(2, p);     }     k = min(k, p + 1);     long double o = 1 - (long double)(1 / (long double)(pow(2, k)));     if (k == 1)       cout << max(n, d / 2) << endl;     else {       ans = 2 * (d / 2) - 1;       cout << ans << endl;     }     return 0;   }
#include<bits/stdc++.h>   using namespace std;   const int maxn=1000025;   const int mod=998244353;   int n,m,i,j,t,k,s,f[maxn],ans,dp[maxn],iv[10];      inline int calc(int x)   {    int ret=x*1ll*(x-1)%mod*(x-2)%mod*iv[6]%mod;//3    ret=(ret+x*1ll*(x-1))%mod;//2    ret=(ret+x)%mod;//1    //printf( calc %d %d n ,x,ret);    return ret;   }      int main()   {    iv[1]=1;iv[2]=(mod+1)/2;iv[3]=(mod+1)/3;iv[6]=iv[2]*1ll*iv[3]%mod;    scanf( %d ,&n);    f[0]=1;s=1;    for (i=1;i<n;++i)    {     f[i]=(1ll*s*(s-1)/2ll%mod+s*1ll+1)%mod;     dp[i]=(f[i]-f[i-1]+mod)%mod;     //f[i]=(f[i]-s+mod)%mod;     s=(s+f[i])%mod;    }    m=n-1;    ans=(1ll*s*(s-1)/2ll%mod+s*1ll+1ll)%mod;    ans=(ans+calc(s))%mod;    ans=(ans-calc((s+mod-f[m])%mod)+mod)%mod;    ans=2ll*(ans+mod)%mod;    ans=(ans-1+mod)%mod;    for (i=n-1;i>0;--i)    {     ans=(ans+dp[i]*1ll*(f[n-i-1]-1))%mod;    }    //ans=(ans-1ll*(f[(n-1)>>1]-1)+mod)%mod;    ans=(ans+mod)%mod;    printf( %d n ,ans);    return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n][3];     for (int i = 0; i < n; i++) {       for (int j = 0; j < 3; j++) {         cin >> a[i][j];       }     }     int c = 1;     for (int i = 0; i < 3; i++) {       int sum = 0;       for (int j = 0; j < n; j++) {         sum += a[j][i];       }       if (sum != 0) {         c = 0;         cout <<  NO ;         break;       }     }     if (c) {       cout <<  YES ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> edge[80005];   int cnt[80005];   unsigned long long ret;   int n;   void dfs(int v, int u) {     cnt[v] = 1;     unsigned long long val = 1ull * n * (n - 1) / 2ull;     for (int i = 0; i < edge[v].size(); i++) {       int to = edge[v][i];       if (to == u) continue;       dfs(to, v);       val -= 1ull * cnt[to] * (cnt[to] - 1) / 2ull;       cnt[v] += cnt[to];     }     val -= 1ull * (n - cnt[v]) * (n - cnt[v] - 1) / 2ull;     ret -= (val * val -             (1ull * (n - cnt[v]) * cnt[v]) * (1ull * (n - cnt[v]) * cnt[v]));   }   int main() {     cin >> n;     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       edge[u].push_back(v);       edge[v].push_back(u);     }     ret = 1ull * n * (n - 1) / 2ull;     ret *= ret;     dfs(rand() % n + 1, -1);     cout << ret << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2000 * 100 + 10;   int endss[maxn];   int main() {     int n, M, T;     cin >> n >> M >> T;     vector<pair<pair<int, int>, int> > ps(2 * n);     for (int i = 0; i < n; i++) {       int h, m, s;       scanf( %d:%d:%d n , &h, &m, &s);       int time = 60 * (60 * h + m) + s;       ps[2 * i] = make_pair(make_pair(time, 0), i);       ps[2 * i + 1] = make_pair(make_pair(time + T - 1, 1), i);     }     sort(ps.begin(), ps.end());     int cur = -1;     int online = 0;     vector<int> ans(n);     bool ok = false;     for (int i = 0; i < (int)(ps).size(); i++) {       if (ps[i].first.second == 0) {         online++;         if (online > M) {           online--;         } else {           if (online == M) ok = true;           cur++;         }         ans[ps[i].second] = cur;         endss[cur]++;       } else {         if (endss[ans[ps[i].second]]) endss[ans[ps[i].second]]--;         if (!endss[ans[ps[i].second]]) online--;       }     }     if (!ok)       puts( No solution );     else {       printf( %d n , cur + 1);       for (int i = 0; i < n; i++) printf( %d n , ans[i] + 1);     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:64000000 )   using namespace std;   const int inf = (int)1e9;   const int mod = inf + 7;   const double eps = 1e-9;   const double pi = acos(-1.0);   int n, a[200200], b[200200];   int mx[200200];   set<pair<int, int> > second;   vector<int> g[200200];   void restore(vector<int> &v) {     for (int i = 0; i < v.size(); i++) {       int x = v[i];       if (mx[x] != -1) second.insert(make_pair(-mx[x], x));     }   }   void solve() {     int sz;     int x;     vector<int> v;     scanf( %d , &sz);     for (int i = 0; i < sz; i++) {       scanf( %d , &x);       x--;       v.push_back(x);       if (mx[x] != -1) second.erase(make_pair(-mx[x], x));     }     if (second.size() == 0) {       printf( 0 0 n );       restore(v);       return;     }     if (second.size() == 1) {       int x = (*second.begin()).second;       printf( %d %d n , x + 1, b[g[x][0]]);       restore(v);       return;     }     __typeof(second.begin()) it = second.begin();     int y = (*it).second;     it++;     int X = (*it).second;     int t = mx[X];     vector<int> &a = g[y];     int l = 0, r = (int)a.size() - 1;     int best = r;     while (l <= r) {       int mid = (l + r) >> 1;       if (a[mid] > t) {         best = mid;         r = mid - 1;       } else         l = mid + 1;     }     printf( %d %d n , y + 1, b[a[best]]);     restore(v);   }   int main() {     memset(mx, -1, sizeof mx);     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d%d , a + i, b + i);       a[i]--;       mx[a[i]] = i;       g[a[i]].push_back(i);     }     for (int i = 0; i < n; i++) {       if (mx[i] == -1) continue;       second.insert(make_pair(-mx[i], i));     }     int q;     scanf( %d , &q);     while (q--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = (int)1e9 + 7;   int a[17];   int c[107][107];   int dp[17][107];   int n;   int main() {     cin >> n;     for (int i = 0; i < 10; i++) cin >> a[i];     for (int i = 0; i <= 100; i++) {       c[i][0] = c[i][i] = 1;       for (int j = 1; j < i; j++) {         c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % M;       }     }     int ans = 0;     dp[10][0] = 1;     for (int dig = 9; dig >= 0; dig--) {       for (int cnt = a[dig]; cnt <= n; cnt++) {         for (int rem = 0; rem + cnt <= n; rem++) {           dp[dig][cnt + rem] =               (dp[dig][cnt + rem] +                (dp[dig + 1][rem] * 1ll * c[cnt + rem - (dig ? 0 : 1)][cnt] % M)) %               M;         }       }     }     for (int len = 1; len <= n; len++) ans = (ans + dp[0][len]) % M;     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int a[101101];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     sort(a, a + n);     int l = 0, r = n - 1, ans = 0;     for (int i = 0; i < n; i++) {       if (a[l] < a[i]) {         ans++;         l++;       } else         r--;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T, class U>   void maximize(T &x, U y) {     if (x < y) x = y;   }   template <class T, class U>   void minimize(T &x, U y) {     if (x > y) x = y;   }   template <class T>   T Abs(T x) {     return (x < (T)0 ? -x : x);   }   namespace task {   const int N = 505;   bool f[N][N];   int a[N], b[N];   int n, k;   long long tot = 0;   void solve() {     cin >> n >> k;     for (int i = 1; i <= n; ++i) {       cin >> a[i] >> b[i];       tot += a[i];       tot += b[i];     }     f[0][0] = true;     for (int i = 1; i <= n; ++i) {       for (int j = 0; j < k; ++j) {         f[i][j] = f[i - 1][(j - a[i] % k + k) % k];         for (int l = 0; l <= min(a[i], k - 1); ++l) {           if ((a[i] - l) % k + b[i] >= k) {             f[i][j] |= f[i - 1][(j - l + k) % k];           }         }       }     }     long long ans = 0;     for (int i = 0; i < k; ++i) {       if (f[n][i]) {         maximize(ans, (tot - 1LL * i) / (1LL * k));       }     }     cout << ans;   }   }  // namespace task   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     task::solve();   }
#include <bits/stdc++.h>   using namespace std;   int ted[1010];   int main() {     memset(ted, 0, sizeof ted);     int n;     cin >> n;     while (n--) {       int x;       cin >> x;       ted[x]++;     }     int ans = 0;     int mx = 0;     for (int i = 1; i <= 1000; i++)       if (ted[i]) {         ans++;         mx = max(mx, ted[i]);       }     cout << mx <<     << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     long long N, M, K;     cin >> N >> K >> M;     vector<long long> A(N);     long long s = 0;     for (int i = 0; i < N; i++) {       cin >> A[i];       s += A[i];     }     sort(A.begin(), A.end());     long double res = (long double)(s + min(M, N * K)) / (long double)N;     for (int i = 0; i < min(N - 1, M); i++) {       s -= A[i];       long long tp = s + min((N - i - 1) * K, M - i - 1);       long double avg = (long double)tp / (long double)(N - i - 1);       res = max(res, avg);     }     cout << fixed << setprecision(20) << res << endl;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     long long n;     cin >> n;     vector<long long> v(n);     for (long long i = 0; i < n; i++) {       cin >> v[i];     }     sort(v.begin(), v.end());     long long count = 0;     while (v.size() > 0) {       count++;       long long num = v[0];       for (long long i = 0; i < v.size(); i++) {         if (v[i] % num == 0) {           v.erase(v.begin() + i, v.begin() + i + 1);           i--;         }       }     }     cout << count << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using lld = long long;   using pi = pair<int, int>;   using pl = pair<lld, lld>;   using vi = vector<int>;   using vvi = vector<vector<int>>;   using vb = vector<bool>;   using vc = vector<char>;   using vl = vector<lld>;   using vp = vector<pi>;   using vs = vector<string>;   using si = stack<int>;   using qi = queue<int>;   using qp = queue<pi>;   using pqi = priority_queue<int>;   const lld mod = 998244353;   int n, mx;   vi t, c, adj;   vb chk;   void input() {     t.clear();     c.clear();     adj.clear();     chk.clear();     cin >> n;     t = vi(n);     c = vi(n);     adj = vi(n, -1);     chk = vb(n);     for (int i = 0; i < n; ++i) cin >> t[i];   }   void go(int cur) {     chk[cur] = true;     int nxt = adj[cur];     if (nxt == -1) return;     if (c[nxt]) {       c[cur] = c[nxt] == 1 ? 2 : 1;       return;     }     c[nxt] = c[cur] == 1 ? 2 : 1;     int t = c[nxt];     go(nxt);     if (t != c[nxt]) {       c[cur] = c[nxt] == 1 ? 2 : 1;     }   }   void solve() {     for (int i = 0; i < n; ++i)       if (t[i] != t[(i + 1) % n]) adj[i] = (i + 1) % n;     int cnt = 0;     for (int i = 0; i < n; ++i) {       if (chk[i]) continue;       c[i] = 1;       go(i);       cnt++;     }     if (cnt == 1)       if (t[n - 1] != t[0] && c[n - 1] == c[0]) c[n - 1] = 3;     int mx = 1;     for (int i = 0; i < n; ++i) mx = max(mx, c[i]);     cout << mx <<   n ;     for (int i = 0; i < n; ++i) cout << c[i] <<    ;     cout <<   n ;   }   int main() {     cin.tie(nullptr);     ios_base::sync_with_stdio(false);     int tc;     cin >> tc;     while (tc--) {       input();       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const int c = 100005;   void solve() {     string s;     cin >> s;     long long o = 0, e = 0, m = 0;     long long ans = INT_MAX;     long long om = 5, em = 5;     for (long long i = 0; i < s.size(); ++i) {       if (i & 1) {         if (s[i] ==  ?  or s[i] ==  1 ) o += 1;         om -= 1;       } else {         if (s[i] ==  1 ) e += 1;         em -= 1;       }       if ((o > e + em) or (e > o + om)) {         ans = min(ans, i + 1);         break;       }     }     om = 5;     em = 5;     o = e = 0;     for (long long i = 0; i < s.size(); ++i) {       if (i & 1) {         if (s[i] ==  1 ) o += 1;         om -= 1;       } else {         if (s[i] ==  1  or s[i] ==  ? ) e += 1;         em -= 1;       }       if ((o > e + em) or (e > o + om)) {         ans = min(ans, i + 1);         break;       }     }     if (ans == INT_MAX) ans = 10;     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long t;     cin >> t;     while (t--) {       solve();     }     return 0;   }