malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long N = 4e5 + 5, M = 998244353, OO = 0x3f3f3f3f;   int t, n;   int a[N], b[N];   bool ok;   set<pair<int, int>> st;   map<pair<int, int>, int> ma;   int main() {     cin >> t;     while (t--) {       cin >> n;       for (int i = 0; i < n; ++i) cin >> a[i];       for (int i = 0; i < n; ++i) cin >> b[i];       if (n % 2 == 1 && a[n / 2] != b[n / 2]) {         cout <<  No  << endl;         continue;       }       for (int i = 0; i < n / 2; ++i) {         st.insert({a[i], a[n - i - 1]});         ma[{a[i], a[n - i - 1]}]++;       }       ok = 1;       for (int i = 0; i < n / 2; ++i) {         if (st.count({b[i], b[n - i - 1]})) {           ma[{b[i], b[n - i - 1]}]--;           if (!ma[{b[i], b[n - i - 1]}]) st.erase({b[i], b[n - i - 1]});         } else if (st.count({b[n - i - 1], b[i]})) {           ma[{b[n - i - 1], b[i]}]--;           if (!ma[{b[n - i - 1], b[i]}]) st.erase({b[n - i - 1], b[i]});         } else           ok = 0;       }       if (ok)         cout <<  Yes  << endl;       else         cout <<  No  << endl;       st.clear();       ma.clear();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 5e5 + 20;   long long n, m, k;   long long col[N];   vector<long long> g[N];   struct edge {     long long u, v;   } e[N];   long long ans;   long long dead[N];   map<pair<long long, long long>, bool> vis;   map<pair<long long, long long>, vector<pair<long long, long long>>>       edges_between;   long long par[N], f[N];   vector<pair<long long, long long>> parhistory, fhistory;   long long root(long long v, bool save_history = 0) {     if (par[v] < 0) return v;     if (save_history) {       parhistory.push_back({v, par[v]});       fhistory.push_back({v, f[v]});     }     long long res = root(par[v], save_history);     f[v] ^= f[par[v]];     par[v] = res;     return res;   }   inline long long merge(long long u, long long v, bool save_history = 0) {     long long ru = root(u, save_history), rv = root(v, save_history);     if (ru == rv) {       if (f[u] == f[v]) return -1;       return 0;     }     if (save_history) {       parhistory.push_back({ru, -1});       fhistory.push_back({ru, 0});     }     if (f[u] == f[v])       f[ru] = 1;     else       f[ru] = 0;     par[ru] = rv;     return 1;   }   int32_t main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> m >> k;     for (long long i = 0; i < n; i++) cin >> col[i], col[i]--;     for (long long i = 0; i < m; i++) {       cin >> e[i].u >> e[i].v;       e[i].u--, e[i].v--;       g[e[i].u].push_back(e[i].v);       g[e[i].v].push_back(e[i].u);     }     memset(par, -1, sizeof par);     for (long long i = 0; i < m; i++) {       long long u = e[i].u, v = e[i].v;       if (col[u] == col[v]) {         if (merge(u, v) == -1) dead[col[u]] = 1;       }     }     long long cnt = 0;     for (long long i = 0; i < k; i++) cnt += (!dead[i]);     for (long long i = 0; i < n; i++) root(i);     ans = 1ll * cnt * (cnt - 1) / 2;     for (long long i = 0; i < m; i++) {       long long u = e[i].u, v = e[i].v;       if (col[u] == col[v]) continue;       if (dead[col[u]] || dead[col[v]]) continue;       long long x = col[u], y = col[v];       if (x > y) swap(x, y);       edges_between[{x, y}].push_back({u, v});       vis[{x, y}] = 1;     }     for (auto p : vis) {       long long x = p.first.first, y = p.first.second;       ans--;       bool ok = 1;       for (pair<long long, long long> ed : edges_between[{x, y}]) {         if (merge(ed.first, ed.second, 1) == -1) {           ok = 0;           break;         }       }       while (parhistory.size()) {         pair<long long, long long> p = parhistory.back();         par[p.first] = p.second;         parhistory.pop_back();       }       while (fhistory.size()) {         pair<long long, long long> p = fhistory.back();         f[p.first] = p.second;         fhistory.pop_back();       }       ans += ok;     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int Maxn = 1000 * 100 + 10;   int m[Maxn], c[Maxn], eatd[Maxn];   int ans;   int INF = 1000 * 1000 * 10 + 10;   int main() {     int N, M, y;     cin >> N >> M >> y >> y;     for (int i = 0; i < N; i++) cin >> m[i];     c[0] = -INF;     c[M + 1] = INF;     for (int i = 1; i <= M; i++) cin >> c[i];     for (int i = 0; i < Maxn; i++) eatd[i] = INF;     for (int i = 0; i < N; i++) {       int ind = lower_bound(c, c + M + 2, m[i]) - c;       if (m[i] - c[ind - 1] < c[ind] - m[i]) {         if (eatd[ind - 1] < m[i] - c[ind - 1])           ans++;         else {           if (eatd[ind - 1] > m[i] - c[ind - 1] && eatd[ind - 1] != INF) ans++;           eatd[ind - 1] = m[i] - c[ind - 1];         }       } else if (m[i] - c[ind - 1] > c[ind] - m[i]) {         if (eatd[ind] != INF) ans++;         eatd[ind] = c[ind] - m[i];       } else {         if (eatd[ind - 1] == INF || eatd[ind - 1] == m[i] - c[ind - 1])           eatd[ind - 1] = m[i] - c[ind - 1];         else           eatd[ind] = c[ind] - m[i];       }     }     if (M == 0)       cout << N;     else       cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 0x3f3f3f3f3f3f3f3f;   long long n, m, mod, a[1000010];   inline long long max(long long x, long long y) { return (x > y ? x : y); }   inline long long min(long long x, long long y) { return (x < y ? x : y); }   struct Segment_Tree {     vector<long long> T[1000010 << 2];     long long bas[1000010 << 2], len[1000010 << 2];     inline void pushup(long long x) {       bas[x] = bas[(x << 1)] + bas[(x << 1 | 1)];       register long long i = 0, j = 0;       for (; i <= len[(x << 1)]; ++i) {         if (j) --j;         for (; j <= len[(x << 1 | 1)]; ++j) {           if (T[(x << 1)][i + 1] - i * mod + bas[(x << 1)] <=               T[(x << 1 | 1)][j]) {             if (j) --j;             break;           }           T[x][i + j] = min(               T[x][i + j],               max(T[(x << 1)][i], T[(x << 1 | 1)][j] + i * mod - bas[(x << 1)]));         }       }       return;     }     inline void build(long long x, long long l, long long r) {       long long mid = (l + r) >> 1;       len[x] = r - l + 1;       T[x].resize(r - l + 3);       for (register long long i = 0; i < r - l + 3; ++i) T[x][i] = inf;       if (l == r) {         T[x][0] = -inf;         T[x][1] = -a[l] + mod;         T[x][2] = inf;         bas[x] = a[l];         return;       }       build((x << 1), l, mid);       build((x << 1 | 1), mid + 1, r);       pushup(x);       return;     }     inline void query(long long x, long long l, long long r, long long lx,                       long long rx, long long &ans) {       if (lx <= l && r <= rx) {         long long L = 0, R = len[x] + 1;         while (L < R) {           long long mid = (L + R + 1) >> 1;           if (T[x][mid] <= ans)             L = mid;           else             R = mid - 1;         }         ans = ans + bas[x] - L * mod;         return;       }       long long mid = (l + r) >> 1;       if (lx <= mid) query((x << 1), l, mid, lx, rx, ans);       if (rx > mid) query((x << 1 | 1), mid + 1, r, lx, rx, ans);       return;     }   } tree;   inline long long read() {     long long x = 0;     char c = getchar();     bool y = 1;     for (; c <  0  || c >  9 ; c = getchar())       if (c ==  - ) y = 0;     for (; c >=  0  && c <=  9 ; c = getchar()) x = (x << 1) + (x << 3) + c - 48;     if (y) return x;     return -x;   }   inline void Input() {     n = read(), m = read(), mod = read();     for (register long long i = 1; i <= n; ++i) a[i] = read();     tree.build(1, 1, n);     return;   }   inline void solve() {     for (register long long i = 1; i <= m; ++i) {       long long l = read(), r = read(), ans = 0;       tree.query(1, 1, n, l, r, ans);       printf( %lld n , ans);     }     return;   }   signed main() {     Input();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e2 + 10;   bool vis[maxn];   int main() {     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       vis[x] = true;     }     int ans = 0;     for (int i = 0; i < k; i++)       if (!vis[i]) ans++;     if (vis[k]) ans++;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = (int)123;   long long dp[N];   void solve() {     long long n, k;     scanf( %lld %lld , &n, &k);     if (k == 1) {       printf( YES %lld n , n - 1);       return;     }     if (n > 31) {       printf( YES %d n , n - 1);       return;     }     long long cur = 0;     for (int i = 1; i <= n; i++) {       cur += ((1LL << i) - 1);       if (k - cur < 0) {         puts( NO );         return;       }       if (k <= dp[n] - ((1LL << (i + 1)) - 1) * dp[n - i]) {         printf( YES %lld n , n - i);         return;       }     }     puts( NO );   }   void precalc() {     for (int i = 1; i <= 31; i++) {       dp[i] = dp[i - 1] * 1LL * 4 + 1;     }   }   int main() {     precalc();     int test;     scanf( %d , &test);     while (test--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[11][11] = {1};     for (int i = 0; i < n; i++) {       a[i][0] = 1;       a[0][i] = 1;     }     for (int i = 1; i < n; i++) {       for (int j = 1; j < n; j++) {         a[i][j] = a[i - 1][j] + a[i][j - 1];       }     }     cout <<   n  << a[n - 1][n - 1];     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   vector<int> v1, v2, ps1, ps2;   string s1, s2, aux1, aux2;   vector<pair<int, int>> ans, aux;   void addLast(string &str, vector<int> &pos) {     for (int i = 0, j = 0; i < str.length(); i = j) {       while (j < str.length() and str[j] == str[i]) {         ++j;       }       pos.push_back(j - 1);     }   }   inline int siz(vector<int> &pos, int p) {     if (p < 0 or !pos.size()) {       return 0;     }     if (p >= pos.size()) {       return pos.back() + 1;     }     return pos[p] + 1;   }   void solve(string &str1, string &str2, vector<pair<int, int>> &ans) {     ps1.clear();     ps2.clear();     addLast(str1, ps1);     addLast(str2, ps2);     int c1 = (int)max(ps1.size() - (ps1.size() and str1.back() ==  a ),                       ps2.size() - (ps2.size() and str2.back() ==  b )),         c2 = (int)max(ps1.size() - (ps1.size() and str1.back() ==  b ),                       ps2.size() - (ps2.size() and str2.back() ==  a ));     if (c1 <= c2) {       int p1 = (int)ps1.size() - 1, p2 = (int)ps2.size() - 1;       if (ps1.size() and str1.back() ==  a ) {         --p1;       }       if (ps2.size() and str2.back() ==  b ) {         --p2;       }       for (bool ok = false; p1 >= 0 or p2 >= 0; --p1, --p2, ok ^= true) {         ans.push_back(!ok ? make_pair(siz(ps1, p1), siz(ps2, p2))                           : make_pair(siz(ps2, p2), siz(ps1, p1)));       }     } else {       int p1 = (int)ps1.size() - 1, p2 = (int)ps2.size() - 1;       if (ps1.size() and str1.back() ==  b ) {         --p1;       }       if (ps2.size() and str2.back() ==  a ) {         --p2;       }       for (bool ok = false; p1 >= 0 or p2 >= 0; --p1, --p2, ok ^= true) {         ans.push_back(!ok ? make_pair(siz(ps1, p1), siz(ps2, p2))                           : make_pair(siz(ps2, p2), siz(ps1, p1)));       }     }   }   int main(void) {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> s1 >> s2;     bool ok = false;     addLast(s1, v1);     addLast(s2, v2);     if (v1.size() > v2.size()) {       swap(v1, v2);       swap(s1, s2);       ok = true;     }     solve(s1, s2, ans);     for (int i = -1; i <= min(3, (int)v1.size()); ++i) {       int x = (int)max(-1, (int)((v2.size() - v1.size()) / 2 - 3)),           y = (int)min(v2.size(), (v2.size() - v1.size()) / 2 + 3);       for (int j = x; j <= y; ++j) {         int p1 = siz(v1, i), p2 = siz(v2, j);         aux2 = s1.substr(0, p1) + s2.substr(p2);         aux1 = s2.substr(0, p2) + s1.substr(p1);         aux.clear();         aux.push_back(make_pair(p1, p2));         solve(aux1, aux2, aux);         if (aux.size() < ans.size()) {           ans = aux;         }       }     }     cout << ans.size() <<   n ;     if (ok) {       for (pair<int, int> &p : ans) {         swap(p.first, p.second);       }     }     for (pair<int, int> p : ans) {       cout << p.first <<     << p.second <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int main() {     scanf( %d%d , &n, &m);     while (n--) {       int a, b, t, ans;       scanf( %d%d%d , &a, &b, &t);       if (a == b) {         printf( %d n , t);         continue;       }       int d = t / (m - 1);       ans = d * (m - 1);       if (d % 2 == 0) {         if (ans + a - 1 < t) {           ans = ans + m - 1 + m - a;           if (b < a)             ans += a - b;           else             ans += a - 1 + b - 1;         } else {           ans += a - 1;           if (b > a)             ans += b - a;           else             ans += m - a + m - b;         }       } else {         if (ans + m - a < t) {           ans += m - 1 + a - 1;           if (b > a)             ans += b - a;           else             ans += m - a + m - b;         } else {           ans += m - a;           if (b < a)             ans += a - b;           else             ans += a - 1 + b - 1;         }       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int rd(int &x) { return scanf( %d , &x); }   int rd(int &x, int &y) { return scanf( %d %d , &x, &y); }   int rd(int &x, int &y, int &z) { return scanf( %d %d %d , &x, &y, &z); }   int rd(int &x, int &y, int &z, int &s) {     return scanf( %d %d %d %d , &x, &y, &z, &s);   }   long long rd(long long &x) { return scanf( %lld , &x); }   long long rd(long long &x, long long &y) { return scanf( %lld %lld , &x, &y); }   long long rd(long long &x, long long &y, long long &z) {     return scanf( %lld %lld %lld , &x, &y, &z);   }   long long rd(long long &x, long long &y, long long &z, long long &s) {     return scanf( %lld %lld %lld %lld , &x, &y, &z, &s);   }   void shaon() { cerr << endl; }   template <typename T, typename... north>   void shaon(T arg, const north &...rest) {     cerr << arg <<    ;     shaon(rest...);   }   long long a, b, x;   int main() {     rd(a, b, x);     long long m;     if (x & 1)       m = (x + 1) / 2;     else       m = (x / 2) + 1;     long long k;     if (x & 1)       k = (x + 1) / 2;     else       k = x / 2;     if (a > b) {       long long r = a - m;       for (int i = 0; i < (r); i++) printf( 0 );       printf( 01 );       long long p = b - k;       for (int i = 0; i < (p); i++) printf( 1 );       long long w = 1;       for (int i = 0; i < (x - 1); i++) {         if (w & 1) {           printf( 0 );         } else           printf( 1 );         w++;       }     } else {       long long r = b - m;       for (int i = 0; i < (r); i++) printf( 1 );       printf( 10 );       long long p = a - k;       for (int i = 0; i < (p); i++) printf( 0 );       long long w = 1;       for (int i = 0; i < (x - 1); i++) {         if (w & 1) {           printf( 1 );         } else           printf( 0 );         w++;       }     }     return 0;   }
#include <bits/stdc++.h>   template <typename T>   inline bool chkmin(T &a, T b) {     return b < a ? a = b, true : false;   }   template <typename T>   inline bool chkmax(T &a, T b) {     return b > a ? a = b, true : false;   }   template <class T>   inline T read(T &x) {     int sign = 1;     char c = getchar_unlocked();     for (; !isdigit(c); c = getchar_unlocked())       if (c ==  - ) sign = -1;     for (x = 0; isdigit(c); c = getchar_unlocked()) x = x * 10 + c -  0 ;     return x *= sign;   }   template <class T>   inline void write(T x) {     if (x == 0) {       putchar_unlocked( 0 );       return;     }     if (x < 0) {       putchar_unlocked( - );       x = -x;     }     static char s[20];     int top = 0;     for (; x; x /= 10) s[++top] = x % 10 +  0 ;     while (top) putchar_unlocked(s[top--]);   }   const int maxN = 500 + 1;   const short inf = 0x3f3f;   struct Edge {     int v, next;   } edge[maxN << 1];   int head[maxN];   inline void addedge(int u, int v) {     static int totedge = 0;     edge[++totedge] = (Edge){v, head[u]}, head[u] = totedge;   }   int size[maxN], col[maxN];   long long G[maxN][maxN];   short dp[maxN][maxN][maxN], f[maxN][maxN];   int n, L;   void dfs(int u, int fa) {     size[u] = 0;     for (int e = head[u]; e; e = edge[e].next) {       int v = edge[e].v;       if (v != fa) {         dfs(v, u);         for (int p = 1; p <= n; ++p) {           if (G[u][p] > L) continue;           int tmp[maxN];           std::fill(tmp, tmp + size[u] + size[v] + 1, +inf);           for (int i = 0; i <= size[u]; ++i)             for (int j = 0; j <= size[v]; ++j) {               chkmin(tmp[i + j], dp[u][i][p] + dp[v][j][p]);               chkmin(tmp[i + j], dp[u][i][p] + f[v][j]);             }           for (int i = 0; i <= size[u] + size[v]; ++i) dp[u][i][p] = tmp[i];         }         size[u] += size[v];       }     }     ++size[u];     std::fill(f[u], f[u] + size[u] + 1, +inf);     for (int p = 1; p <= n; ++p) {       dp[u][size[u]][p] = +inf;       if (G[u][p] > L) {         for (int i = 0; i <= size[u]; ++i) dp[u][i][p] = +inf;         continue;       }       for (int i = 0; i < size[u]; ++i)         chkmin(f[u][i + 1], short(dp[u][i][p] + !col[p]));     }   }   int main() {     if (fopen( tmp.in ,  r )) {       freopen( tmp.in ,  r , stdin);       freopen( tmp.out ,  w , stdout);     }     int tot = 0;     read(n), read(L);     for (int i = 1; i <= n; ++i) tot += read(col[i]);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j) G[i][j] = i == j ? 0 : 0x3f3f3f3f3f3f3f3fll;     for (int i = 1; i < n; ++i) {       int u, v;       long long w;       read(u), read(v), read(w);       addedge(u, v), addedge(v, u);       chkmin(G[u][v], w), chkmin(G[v][u], w);     }     for (int k = 1; k <= n; ++k)       for (int i = 1; i <= n; ++i)         for (int j = 1; j <= n; ++j) chkmin(G[i][j], G[i][k] + G[k][j]);     dfs(1, 0);     short ans = inf;     for (int i = 0; i <= tot; ++i) chkmin(ans, f[1][i]);     write(ans == inf ? -1 : ans), putchar_unlocked(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, ans;   long long f(long long x) { return 3 * x * (x + 1) / 2 - x; }   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     ans = 0;     for (long long i = 1; f(i) <= n; i++) {       if ((n + i) % 3 == 0) {         ans++;       }     }     cout << ans;     return ((int)228 / 1488);   }
#include <bits/stdc++.h>   using namespace std;   int n = 0, c = 0;   float y = 0;   int main() {     if (!n) {       scanf( %d , &n);       main();     } else if (c == n) {       printf( %.3f , 5 + y / n);       return 0;     } else {       float x;       scanf( %*f %f , &x);       y += x;       c++;       main();     }   }
#include <bits/stdc++.h>   using namespace std;   vector<int> con[100005];   int coun[100005];   void serc(int x, int l) {     coun[l]++;     for (int i = 0; i < con[x].size(); i++) {       serc(con[x][i], l + 1);     }     return;   }   int main() {     int n;     cin >> n;     int a;     for (int i = 2; i <= n; i++) {       cin >> a;       con[a].push_back(i);     }     serc(1, 1);     int k = 0;     for (int i = 1; i <= n; i++) {       k += coun[i] % 2;     }     printf( %d n , k);   }
#include <bits/stdc++.h>   using namespace std;   long long cil(long long x, long long y) {     if (x % y == 0) {       return x / y;     };     return x / y + 1;   }   void solve() {     long long n;     cin >> n;     vector<long long> sizes;     vector<vector<long long>> a(n);     for (long long i = 0; i < n; i++) {       long long x;       cin >> x;       sizes.push_back(x);       for (long long j = 0; j < sizes.back(); j++) {         cin >> x;         a[i].push_back(x);       }     }     long long m;     cin >> m;     set<vector<long long>> s;     for (long long i = 0; i < m; i++) {       vector<long long> t;       for (long long j = 0; j < n; j++) {         long long x;         cin >> x;         x--;         t.push_back(x);       }       s.insert(t);     }     vector<long long> t;     for (long long i = 0; i < n; i++) t.push_back(sizes[i] - 1);     auto sum = [&](vector<long long> p) {       long long ans = 0;       for (long long i = 0; i < n; i++) {         ans += a[i][p[i]];       }       return ans;     };     priority_queue<pair<long long, vector<long long>>> pq;     pq.push({sum(t), t});     set<vector<long long>> already;     already.insert(t);     while (!pq.empty()) {       auto root = pq.top();       pq.pop();       long long value = root.first;       vector<long long> v = root.second;       if (s.find(v) == s.end()) {         for (auto x : v) cout << x + 1 <<    ;         cout <<   n ;         return;       }       for (long long i = 0; i < n; i++) {         vector<long long> t;         for (long long j = 0; j < n; j++) {           t.push_back(v[j]);         }         if (t[i] > 0) {           t[i]--;           if (already.find(t) == already.end()) pq.push({sum(t), t});           already.insert(t);         }       }     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long tt = 1;     for (long long tc = 1; tc <= tt; tc++) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int N = (int)1e5 + 5;   int _ = 1;   int n, q;   int a[N], pos[N];   int nex[N], blo;   int calc(int x) {     for (int i = 1; i <= blo; i++) x = a[x];     return x;   }   void work() {     scanf( %d%d , &n, &q);     blo = sqrt(n) + 1;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) pos[a[i]] = i;     for (int i = 1; i <= n; i++) nex[i] = calc(i);     while (q--) {       int op;       scanf( %d , &op);       if (op == 1) {         int x, y;         scanf( %d%d , &x, &y);         swap(pos[a[x]], pos[a[y]]);         swap(a[x], a[y]);         nex[x] = calc(x);         nex[y] = calc(y);         for (int i = 1; i <= blo; i++) {           x = pos[x];           y = pos[y];         }         int ex = calc(x), ey = calc(y);         for (int i = 1; i <= blo; i++) {           nex[x] = ex;           nex[y] = ey;           x = a[x];           y = a[y];           ex = a[ex];           ey = a[ey];         }       } else {         int x, y;         scanf( %d%d , &x, &y);         while (y >= blo) {           x = nex[x];           y -= blo;         }         while (y) {           x = a[x];           y--;         }         printf( %d n , x);       }     }   }   int main() {     while (_--) {       work();     }     return 0;   }
#include <bits/stdc++.h>   int main() {     char a[60];     int l;     while (scanf( %s , a) != EOF) {       int b = 0;       l = strlen(a);       for (int i = 0; i < l; i++) {         if (a[i] != a[l - i - 1]) {           b++;         }       }       if (b) printf( %d n , l);       if (b == 0) {         int s = 0;         for (int i = 0; i < l - 1; i++) {           if (a[i] == a[i + 1]) s++;         }         if (s == l - 1)           printf( 0 n );         else           printf( %d n , l - 1);       }     }     return 0;   }