malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   inline int read() {     int x = 0;     char c = getchar();     bool f = 0;     while (!isdigit(c)) f |= (c ==  - ), c = getchar();     while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();     return f ? -x : x;   }   int n, m, t;   int sq[500005], a[500005], pos[500005], cnt[500005], ans[500005], st[500005],       top;   struct node {     int l, r, id;   } q[500005];   int nowx, nowy;   inline bool operator<(node x, node y) {     return (sq[x.l] ^ sq[y.l]) ? x.l < y.l                                : ((sq[x.l] & 1) ? x.r < y.r : x.r > y.r);   }   inline void Add(int x) {     if (cnt[a[x]] == 1) {       st[pos[a[x]]] = st[top];       pos[st[top]] = pos[a[x]];       pos[a[x]] = st[top--] = 0;     }     cnt[a[x]]++;     if (cnt[a[x]] == 1) st[++top] = a[x], pos[a[x]] = top;   }   inline void Delete(int x) {     if (cnt[a[x]] == 1) {       st[pos[a[x]]] = st[top];       pos[st[top]] = pos[a[x]];       pos[a[x]] = st[top--] = 0;     }     cnt[a[x]]--;     if (cnt[a[x]] == 1) st[++top] = a[x], pos[a[x]] = top;   }   int main() {     n = read(), t = sqrt(n);     for (register int i = 1; i <= n; ++i) a[i] = read(), sq[i] = i / t;     m = read();     for (register int i = 1; i <= m; ++i)       q[i].l = read(), q[i].r = read(), q[i].id = i;     sort(q + 1, q + m + 1);     nowx = 1, nowy = 0;     for (register int i = 1; i <= m; ++i) {       while (nowx < q[i].l) Delete(nowx++);       while (nowx > q[i].l) Add(--nowx);       while (nowy > q[i].r) Delete(nowy--);       while (nowy < q[i].r) Add(++nowy);       ans[q[i].id] = st[top];     }     for (register int i = 1; i <= m; ++i) printf( %d n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int x1, x2, x3;     cin >> x1 >> x2 >> x3;     int min, max;     int t = (x1 < x2) ? x1 : x2;     min = (t < x3) ? t : x3;     t = (x1 > x2) ? x1 : x2;     max = (t > x3) ? t : x3;     cout << max - min;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   const int p = 998244353;   int n, k, cnt, a[N], d[N], jc[N], ny[N];   long long s = 1, ans;   inline int read() {     int ans = 0;     char c = getchar();     while (c < 48 || c > 57) c = getchar();     while (c >= 48 && c <= 57)       ans = (ans << 3) + (ans << 1) + (c ^ 48), c = getchar();     return ans;   }   inline long long ksm(long long x, int y) {     long long z = 1;     while (y) {       if (y & 1) z = z * x % p;       x = x * x % p, y >>= 1;     }     return z;   }   inline long long C(int x, int y) {     return 1ll * jc[x] * ny[y] % p * ny[x - y] % p;   }   int main() {     n = read(), k = read() % p;     for (register int i = 1; i <= n; ++i) {       int u = read();       if (u != a[cnt])         a[++cnt] = u;       else         s = s * k % p;     }     if (a[1] == a[cnt]) --cnt, s = s * k % p;     if (cnt <= 1) {       putchar(48);       return 0;     }     d[0] = jc[0] = 1, ans = ksm(k, cnt);     for (register int i = 1; i <= cnt; ++i)       d[i] = 1ll * d[i - 1] * (k - 2) % p, jc[i] = 1ll * jc[i - 1] * i % p;     ny[cnt] = ksm(jc[cnt], p - 2);     for (register int i = cnt - 1; i >= 0; --i)       ny[i] = 1ll * ny[i + 1] * (i + 1) % p;     for (register int i = 0; (i << 1) <= cnt; ++i)       ans = (ans - C(cnt, i) * C(cnt - i, i) % p * d[cnt - (i << 1)] % p + p) % p;     ans = ans * ny[2] % p * s % p;     printf( %lld , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   long long powmod(long long a, long long b) {     long long res = 1;     a %= mod;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   int v[100066];   vector<int> prime;   int mu[100066];   void init() {     int N = 100000;     for (int i = 2; i <= N; i++) {       if (!v[i]) {         mu[i] = 1;         v[i] = i;         prime.push_back(i);       }       for (auto p : prime) {         if (p > v[i] || i > N / p) break;         v[i * p] = p;         if (i % p == 0)           mu[i * p] = 0;         else           mu[i * p] = -mu[i];       }     }   }   long long solve(vector<pair<int, int> > vec) {     long long sum = 0, all = 0;     long long all1 = 0;     for (auto x : vec) {       sum = (sum + 1ll * x.first * x.second) % mod;       all = (all + x.second) % mod;       all1 = (all1 + x.second) % (mod - 1);     }     long long pp = powmod(2, all1 - 2 + mod - 1) * ((all - 1 + mod) % mod) % mod;     long long ret = 0;     long long two0 = powmod(2, all1 - 3 + mod - 1);     long long two1 = two0 * 2 % mod;     long long two2 = two1 * 2 % mod;     long long qq = two1 + (all - 2 + mod) * two0;     qq = qq % mod;     for (auto x : vec) {       ret += pp * x.first % mod * x.first % mod * x.second % mod;       ret %= mod;       long long tmp = (sum + mod - x.first) % mod;       tmp = 1ll * x.second * x.first % mod * tmp % mod * qq % mod;       ret = (ret + tmp) % mod;     }     return ret;   }   int n;   vector<pair<int, int> > vec, V[100066];   int main() {     init();     scanf( %d , &n);     int x, y;     for (int i = 1; i <= n; i++) {       scanf( %d%d , &x, &y);       vec.push_back(make_pair(x, y));       for (int j = 1; 1ll * j * j <= x; j++) {         if (x % j) continue;         V[j].push_back(make_pair(x, y));         if (x / j != j) V[x / j].push_back(make_pair(x, y));       }     }     long long ans = solve(vec);     for (int i = 2; i <= 100000; i++) {       long long tmp = (-solve(V[i]) * mu[i] + mod) % mod;       ans = (ans + tmp) % mod;     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (!(ch >=  0  && ch <=  9 )) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + (ch -  0 );       ch = getchar();     }     return x * f;   }   struct edge {     int next, to;   } e[900500];   vector<int> v[900500];   int cnt, head[900500], size[900500], col[900500];   bool used[900500], vis[900500];   inline void ins(int u, int v) {     e[++cnt].to = v;     e[cnt].next = head[u];     head[u] = cnt;   }   inline void insert(int u, int v) {     ins(u, v);     ins(v, u);   }   void dfs(int x) {     int j = 1;     vis[x] = 1;     for (int i = 0; i < size[x]; i++) used[col[v[x][i]]] = 1;     for (int i = 0; i < size[x]; i++)       if (!col[v[x][i]]) {         for (; used[j]; j++)           ;         used[col[v[x][i]] = j] = 1;       }     for (int i = 0; i < size[x]; i++) used[col[v[x][i]]] = 0;     for (int i = head[x]; i; i = e[i].next)       if (!vis[e[i].to]) dfs(e[i].to);   }   int main() {     int n = read(), m = read(), ans = 0;     for (int i = 1; i <= n; i++) {       size[i] = read();       for (int j = 1; j <= size[i]; j++) v[i].push_back(read());       ans = max(ans, size[i]);     }     for (int i = 1; i < n; i++) insert(read(), read());     printf( %d n , ans ? ans : 1);     dfs(1);     for (int i = 1; i <= m; i++) printf( %d  , col[i] ? col[i] : 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Z = (int)3e3 + 228;   const int N = (int)1e6 + 228;   const int INF = (int)1e9 + 228;   const int MOD = (int)1e9 + 7;   int n, d;   long long a[N], delta[N], k;   bool can(long long mid) {     fill(delta + 1, delta + 1 + n, 0LL);     for (int i = 1; i <= n; i++) {       delta[max(1, i - d)] += a[i];       delta[i + d + 1] -= a[i];     }     long long cur = 0, res = 0;     for (int i = 1; i <= n; i++) {       cur += delta[i];       if (cur < mid) {         res += mid - cur;         if (res > k) return false;         delta[i + 2 * d + 1] -= mid - cur;         cur = mid;       }     }     return true;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> d >> k;     for (int i = 1; i <= n; i++) cin >> a[i];     long long l = 0, r = 2e18 + 5;     while (l < r) {       long long mid = (l + r + 1) / 2;       if (can(mid))         l = mid;       else         r = mid - 1;     }     cout << l;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool shown[100001];   vector<pair<int, int> > v;   vector<int> cycle;   vector<vector<int> > ans;   int main() {     int n, tmp;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &tmp);       v.push_back(make_pair(tmp, i));     }     sort(v.begin(), v.end());     for (int i = 0; i < n; i++) {       int j = i;       while (!shown[v[j].second]) {         shown[v[j].second] = true;         cycle.push_back(v[j].second);         j = v[j].second;       }       if (cycle.size() != 0) {         sort(cycle.begin(), cycle.end());         ans.push_back(cycle);         cycle.clear();       }     }     printf( %d n , ans.size());     for (int i = 0; i < ans.size(); i++) {       printf( %d , ans[i].size());       for (int j = 0; j < ans[i].size(); j++) printf(  %d , ans[i][j] + 1);       printf(  n );     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s1, s2;     long long int n, c11 = 0, c00 = 0, c10 = 0, c01 = 0, p1 = 0, p2 = 0;     cin >> n >> s1 >> s2;     n *= 2;     for (int i = 0; i < n; i++) {       if (s1[i] == s2[i]) {         if (s1[i] ==  1 )           c11++;         else           c00++;       } else {         if (s1[i] ==  1 )           c10++;         else           c01++;       }     }     if (c11 % 2) {       p1 = c11 / 2 + 1;       p2 = c11 / 2;       if (c01 <= c10) {         p2 += c01;         p1 += c01 + (c10 - c01) / 2;       } else {         p2 += c10 + (c01 - c10) / 2 + (c01 - c10) % 2;         p1 += c10;       }     } else {       p1 = c11 / 2;       p2 = c11 / 2;       if (c01 <= c10) {         p2 += c01;         p1 += c01 + (c10 - c01) / 2 + (c10 - c01) % 2;       } else {         p2 += c10 + (c01 - c10) / 2;         p1 += c10;       }     }     if (p1 > p2)       cout <<  First  << endl;     else if (p1 == p2)       cout <<  Draw  << endl;     else       cout <<  Second  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, k, x, r, z, sol;   int main() {     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> x;       if (r > 0) {         x = x - k + r;         sol++;       }       z = x / k;       sol += z;       r = x % k;     }     if (r > 0) {       sol++;     }     cout << sol;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1E6;   int n, q, sz = 1;   long long value[6];   long long dp[MAXN];   inline void upData(int v, long long w) {     for (int i = MAXN - 1; i >= v; --i) dp[i] = max(dp[i], dp[i - v] + w);   }   inline void Divide(int x) {     int v = 3 * sz, all = min(MAXN / v, n);     for (int i = 1; i < all; i <<= 1) upData(v * i, 1ll * value[x] * i), all -= i;     upData(v * all, 1ll * value[x] * all);   }   int main(void) {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n, n = 3 * (n - 1);     for (int i = 0; i < 6; ++i) cin >> value[i];     for (int i = 3; i < MAXN; ++i) {       int num = i, base = 0;       while (num) {         if (((num % 10) % 3) == 0) dp[i] += 1ll * value[base] * ((num % 10) / 3);         num /= 10, ++base;       }     }     for (int i = 0; i < 6; ++i) Divide(i), sz *= 10;     cin >> q;     while (q--) cin >> n, cout << dp[n] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000000 + 7;   map<int, vector<int>> mp;   vector<int> cur(1, -1), goal(1, -1), done(1, -1);   vector<int> ans;   int c;   void funct(int node, int level, int even, int odd) {     int r = level % 2;     done[node] = 1;     if (r == 1 && odd == 1)       cur[node] = 1 - cur[node];     else if (r == 0 && even == 1)       cur[node] = 1 - cur[node];     if (cur[node] != goal[node]) {       c++;       ans.push_back(node);       cur[node] = goal[node];       if (level % 2 == 0)         even = 1 - even;       else         odd = 1 - odd;     }     for (int i = 0; i < mp[node].size(); i++) {       if (done[mp[node][i]] == 0) funct(mp[node][i], level + 1, even, odd);     }   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       mp[a].push_back(b);       mp[b].push_back(a);     }     int num;     for (int i = 1; i <= n; i++) {       scanf( %d , &num);       cur.push_back(num);     }     for (int i = 1; i <= n; i++) {       scanf( %d , &num);       goal.push_back(num);       done.push_back(0);     }     c = 0;     int level = 0, even = 0, odd = 0;     funct(1, level, even, odd);     cout << c << endl;     if (c > 0) {       int i = 0;       while (i < ans.size()) {         printf( %d n , ans[i]);         i++;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, a[60], b[60];     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     cin >> m;     for (int i = 0; i < m; i++) cin >> b[i];     int BG = -1;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (b[j] % a[i] == 0) {           if (b[j] / a[i] > BG) {             BG = b[j] / a[i];           }         }       }     }     int ans = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (b[j] % a[i] == 0 && b[j] / a[i] == BG) {           ans++;         }       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   using ll = long long;   using ld = long double;   ll mod = 998244353;   ll gcd(ll a, ll b) {     if (a == 0 or b == 0) return a + b;     return gcd(b, a % b);   }   ll sum(ll a, ll b) {     a += b;     a %= mod;     return a;   }   ll sub(ll a, ll b) {     a += mod - b;     a %= mod;     return a;   }   inline ll mul(ll a, ll b) {     if (a * b < mod) return a * b;     return a * b % mod;   }   inline ll pew(ll a, ll b) {     ll res = 1;     while (b) {       if (b & 1) res = mul(res, a);       a = mul(a, a);       b /= 2;     }     return res;   }   int parent[600001];   int rnk[600001];   int suk[600001];   void make_set(int v) {     parent[v] = v;     rnk[v] = 0;     suk[v] = 0;   }   int find_set(int v) {     if (v == parent[v]) return v;     return parent[v] = find_set(parent[v]);   }   void union_sets(int a, int b) {     a = find_set(a);     b = find_set(b);     if (a != b and (suk[a] * suk[b] == 0)) {       if (rnk[a] < rnk[b]) swap(a, b);       parent[b] = a;       if (rnk[a] == rnk[b]) ++rnk[a];       suk[a] += suk[b];     }   }   vector<ll> primes(ll cur) {     vector<ll> res;     if (cur <= 1) return res;     for (ll j = 2; j * j <= cur; j++) {       if (cur % j == 0) {         res.push_back(j);         while (cur % j == 0) {           cur /= j;         }       }     }     if (cur != 1) res.push_back(cur);     return res;   }   int main() {     ios_base::sync_with_stdio(false);     ll n;     cin >> n;     srand(35324);     vector<ll> kek(n);     for (int i = 0; i < n; i++) {       cin >> kek[i];     }     vector<ll> lul(n);     for (int i = 0; i < n; i++) {       lul[i] = kek[i];     }     random_shuffle(lul.begin(), lul.end());     ll bst = n;     for (int q = 0; q < n and q < 23; q++) {       ll cur = lul[q] - 1;       vector<ll> pr = primes(cur);       for (int j = 0; j < pr.size(); j++) {         ll p = pr[j];         ll cnt = 0;         for (int i = 0; i < n; i++) {           ll a = kek[i] % p;           if (kek[i] == a) {             cnt += p - a;           } else {             cnt += min(a, p - a);           }         }         bst = min(bst, cnt);       }       cur = lul[q];       pr = primes(cur);       for (int j = 0; j < pr.size(); j++) {         ll p = pr[j];         ll cnt = 0;         for (int i = 0; i < n; i++) {           ll a = kek[i] % p;           if (kek[i] == a) {             cnt += p - a;           } else {             cnt += min(a, p - a);           }         }         bst = min(bst, cnt);       }       cur = lul[q] + 1;       pr = primes(cur);       for (int j = 0; j < pr.size(); j++) {         ll p = pr[j];         ll cnt = 0;         for (int i = 0; i < n; i++) {           ll a = kek[i] % p;           if (kek[i] == a) {             cnt += p - a;           } else {             cnt += min(a, p - a);           }         }         bst = min(bst, cnt);       }     }     cout << bst << endl;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int flag = 1;     int a, b, c, d;     cin >> a >> b >> c >> d;     if ((a + b) % 2 == 0) {     } else       flag = -1;     if (a + d == 0) {       if (flag == 1) {         cout <<  Tidak Tidak Ya Tidak               <<   n ;         return;       } else {         cout <<  Tidak Ya Tidak Tidak               <<   n ;         return;       }     }     if (b + c == 0) {       if (flag == 1) {         cout <<  Tidak Tidak Tidak Ya               <<   n ;         return;       } else {         cout <<  Ya Tidak Tidak Tidak               <<   n ;         return;       }     }     if (flag == 1) {       cout <<  Tidak Tidak Ya Ya             <<   n ;       return;     } else {       cout <<  Ya Ya Tidak Tidak             <<   n ;       return;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     int _ = 1;     cin >> _;     while (_--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     vector<int> a(n);     for (auto &x : a) cin >> x;     sort(a.begin(), a.end());     set<int> s;     int ans = 0, x;     for (int i = 0; i < n; i++) {       x = a[i];       if (s.find(x) != s.end()) {         while (1) {           if (s.find(x) != s.end())             ans++;           else             break;           x++;         }       }       s.insert(x);     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int dx[] = {-1, 1, 0, 0};   const int dy[] = {0, 0, -1, 1};   const int max_n = 1000;   char a[max_n][max_n];   int res[max_n][max_n], val[max_n * max_n];   vector<pair<int, int> > comp[max_n * max_n];   bool used[10];   bool range(int x, int l, int r) { return ((l <= x) && (x <= r)); }   int main() {     int n, m, r = 0;     scanf( %d%d n , &n, &m);     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) scanf( %c , &a[i][j]);       scanf(  n );     }     memset(res, -1, sizeof(res));     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j)         if (a[i][j] ==  . )           if ((j < m - 1) && (a[i][j + 1] ==  . )) {             res[i][j] = res[i][j + 1] = r++, a[i][j] = a[i][j + 1] =  ~ ;           } else if ((i < n - 1) && (a[i + 1][j] ==  . ))             res[i][j] = res[i + 1][j] = r++, a[i][j] = a[i + 1][j] =  ~ ;           else {             for (int d = 0; d < 4; ++d)               if (range(i + dx[d], 0, n - 1) && range(j + dy[d], 0, m - 1) &&                   (a[i + dx[d]][j + dy[d]] !=  # )) {                 res[i][j] = res[i + dx[d]][j + dy[d]];                 break;               }             if (res[i][j] != -1) continue;             printf( -1 n );             return 0;           }     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j)         if (res[i][j] != -1) comp[res[i][j]].push_back(make_pair(i, j));     for (int rc = 0; rc < r; ++rc) {       memset(used, 0, sizeof(used));       for (int k = 0; k < (int)comp[rc].size(); ++k)         for (int d = 0; d < 4; ++d) {           int cur = res[comp[rc][k].first + dx[d]][comp[rc][k].second + dy[d]];           if (cur < rc) used[val[cur]] = true;         }       for (int k = 0; k < 10; ++k)         if (!used[k]) {           val[rc] = k;           break;         }     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j)         printf( %c , res[i][j] == -1 ?  #  :  0  + val[res[i][j]]);       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k;   int a[10000];   int main() {     cin >> n >> m >> k;     for (int i = 0; i < n; i++) scanf( %d , a + i);     if (n % 2 == 0)       puts( 0 );     else {       long long r = m / ((n + 1) / 2);       long long hi = (1 << 30);       for (int i = 0; i < n; i += 2) hi = min(hi, (long long)a[i]);       cout << min(hi, r * k) << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MaxN = 1e5 + 5;   int main() {     int n, f[MaxN], cnt[MaxN], mm = 0, ans = 0;     scanf( %d , &n);     memset(f, 0, sizeof(f));     memset(cnt, 0, sizeof(cnt));     for (int i = 1; i <= n; i++) {       int a;       scanf( %d , &a);       cnt[f[a]]--;       f[a]++;       cnt[f[a]]++;       mm = max(mm, f[a]);       bool flag = 0;       if (cnt[1] == i)         flag = 1;       else if (cnt[i] == 1)         flag = 1;       else if (cnt[1] == 1 && cnt[mm] * mm == i - 1)         flag = 1;       else if (cnt[mm - 1] * (mm - 1) == i - mm && cnt[mm] == 1)         flag = 1;       if (flag == 1) ans = i;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll OO = 0x3f3f3f3f3f3f3f3fLL;   int di[8] = {0, 0, 1, -1, -1, 1, -1, 1};   int dj[8] = {1, -1, 0, 0, 1, 1, -1, -1};   string ys =  YES , no =  NO ;   const int N = 1e5 + 5, M = 5 * (1 << 10) + 10;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string s;       cin >> s;       bool ok = 0;       for (int i = 0; i < n; i++) {         int cnta = 0, cntb = 0;         for (int j = i; j < n; j++) {           cnta += (s[j] ==  a );           cntb += (s[j] ==  b );           if (cnta == cntb) {             cout << i + 1 <<     << j + 1 <<   n ;             ok = 1;             goto out;           }         }       }     out:;       if (!ok) cout <<  -1 -1  <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int n;   string a;   void input() {     cin >> n;     cin >> a;   }   void solve() {     int ans = 0;     for (int i = 1; i < n; ++i) {       ans += (a[i] == a[i - 1]);     }     cout << (ans + 1) / 2 <<   n ;   }   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       input();       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int A = 0, B = 0, C = 0;   void add(char o) {     if (o ==  A ) {       A++;     } else {       if (o ==  B ) {         B++;       } else {         if (o ==  C ) {           C++;         }       }     }   }   void sub(char o) {     if (o ==  A ) {       A--;     } else {       if (o ==  B ) {         B--;       } else {         if (o ==  C ) {           C--;         }       }     }   }   int main() {     char c[3][3];     for (int i = 0; i < 3; i++) {       cin >> c[i][0];       cin >> c[i][1];       cin >> c[i][2];       if (c[i][1] ==  > ) {         add(c[i][0]);         sub(c[i][2]);       } else {         if (c[i][1] ==  < ) {           sub(c[i][0]);           add(c[i][2]);         }       }     }     if (A == 0 && B == 0 && C == 0) {       cout <<  Impossible ;     } else {       if (A == -2 && B == 0 && C == 2) {         cout <<  ABC ;       } else {         if (B == -2 && C == 0 && A == 2) {           cout <<  BCA ;         } else {           if (C == -2 && B == 0 && A == 2) {             cout <<  CBA ;           } else {             if (A == -2 && C == 0 && B == 2) {               cout <<  ACB ;             } else {               if (C == -2 && A == 0 && B == 2) {                 cout <<  CAB ;               } else {                 if (C == 2 && A == 0 && B == -2) {                   cout <<  BAC ;                 }               }             }           }         }       }     }     return 0;   }