malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   unordered_map<long long, vector<long long>> m3;   vector<long long int> v;   long long a;   int dfs(long long i, long long p) {     long long k, k1, j, t;     k = -1;     k1 = 0;     for (j = 0; j < m3[i].size(); j++) {       long long d = m3[i][j];       if (d != p) {         t = dfs(d, i);         if (t == 1) {           if (v[d] != v[i]) {             k1 = -1;           }         } else {           k1 = -1;         }       }     }     if (k1 == 0) {       return 1;     }     return -1;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long i, j, b, n, x, y, z, t, k, sum, sum1;     vector<long long int> v1, v2, v3, v4;     string s, s1, s2;     unordered_map<long long, long long> m1, m2, m7;     unordered_map<long long, vector<long long>> m;     t = 1;     while (t--) {       cin >> n;       for (i = 0; i < n - 1; i++) {         cin >> a >> b;         m3[a].push_back(b);         m3[b].push_back(a);       }       a = 0;       v.push_back(0);       for (i = 0; i < n; i++) {         cin >> j;         v.push_back(j);       }       j = 1;       x = -1;       for (i = 1; i <= n; i++) {         for (k = 0; k < m3[i].size(); k++) {           if (v[i] != v[m3[i][k]]) {             x = i;             y = m3[i][k];             break;           }         }       }       if (x == -1) {         cout <<  YES  << endl;         cout << 1;         return 0;       }       for (j = 0; j < m3[x].size(); j++) {         i = dfs(m3[x][j], x);         if (i == -1) break;       }       if (i == 1) {         cout <<  YES  << endl;         cout << x;         return 0;       }       x = y;       for (j = 0; j < m3[x].size(); j++) {         i = dfs(m3[x][j], x);         if (i == -1) break;       }       if (i == 1) {         cout <<  YES  << endl;         cout << y;         return 0;       }       cout <<  NO  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     long long t = 1;     while (t--) {       long long n, d;       cin >> n >> d;       vector<long long> temp(n);       vector<long long> temp2(n);       for (long long i = 0; i < n; i++) {         cin >> temp[i];       }       for (long long i = 0; i < n; i++) {         cin >> temp2[i];       }       long long i = 0;       long long j = n - 1;       if (d == 1) {         cout << 1 << endl;         continue;       }       long long score = temp[d - 1] + temp2[0];       long long ans = d;       while (i < d - 1) {         if (temp[i] + temp2[j] <= score) {           ans--;           i++;           j--;         } else {           i++;         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ifstream ff( file.txt );     int n, k;     cin >> n >> k;     string s1;     cin >> s1;     n = s1.length();     if (k == 0) {       cout << s1 << endl;       return 0;     }     int j = 0;     bool b1 = false, b2 = false;     for (int i = 0; i < n - 2; i++) {       j++;       if ((i + 1) % 2 != 0 && s1.substr(i, 3) ==  447 ) {         b1 = true;         break;       } else if ((i + 1) % 2 != 0 && s1.substr(i, 3) ==  477 ) {         b2 = true;         break;       }     }     if (b1 == false && b2 == false) {       j++;     }     if (b2 == true) {       j--;     }     for (int i = 0; i < j; i++) {       if (s1.substr(i, 2) ==  47 ) {         if ((i + 1) % 2 == 1) {           s1[i] =  4 ;           s1[i + 1] =  4 ;         } else {           s1[i] =  7 ;           s1[i + 1] =  7 ;         }         k--;       }       if (k == 0) {         cout << s1 << endl;         return 0;       }     }     if (b1 == true) {       if (k % 2 != 0) {         if (j % 2 == 0) {           s1[j] =  4 ;         } else {           s1[j] =  7 ;         }       }     }     if (b2 == true) {       if (k % 2 != 0) {         if (j % 2 == 0) {           s1[j + 1] =  4 ;         } else {           s1[j + 1] =  7 ;         }       }     }     cout << s1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int get() {     int x = 0;     char s = getchar();     while (s <  0  || s >  9 ) s = getchar();     while (s >=  0  && s <=  9 )       x = (x << 3) + (x << 1) + (s ^ 48), s = getchar();     return x;   }   int Min(const int x, const int y) {     if (x < y) return x;     return y;   }   const int M = 1e5 + 5, mo = 1e9 + 7;   int n, m, head[M], cntedge, vis[M], dfn[M], low[M], tot, cntscc, scc[M], siz[M],       dep[M], f[M][17], w[M];   vector<int> G[M];   stack<int> st;   struct edge {     int to, nxt;     edge() {}     edge(const int T, const int NX) { to = T, nxt = NX; }   } e[M << 1];   void add(const int u, const int v) {     e[++cntedge] = edge(v, head[u]), head[u] = cntedge;   }   int pow(int x, int k) {     int ans = 1;     while (k) {       if (k & 1) ans = 1ll * ans * x % mo;       x = 1ll * x * x % mo;       k >>= 1;     }     return ans;   }   void tarjan(const int u, const int fa) {     dfn[u] = low[u] = ++tot;     vis[u] = 1;     st.push(u);     int v;     for (int i = head[u]; i; i = e[i].nxt) {       v = e[i].to;       if (v == fa || vis[v] == 2) continue;       if (!vis[v]) tarjan(v, u);       low[u] = Min(low[u], low[v]);     }     if (dfn[u] == low[u]) {       ++cntscc;       do {         v = st.top(), st.pop();         scc[v] = cntscc;         vis[v] = 2;         ++siz[cntscc];       } while (v ^ u);     }   }   void dfs(const int x, const int fa) {     dep[x] = dep[fa] + 1;     f[x][0] = fa;     w[x] = w[fa] + (siz[x] > 1);     for (int i = 1; i < 17; ++i) f[x][i] = f[f[x][i - 1]][i - 1];     for (int i = 0; i < G[x].size(); ++i)       if (G[x][i] ^ fa) dfs(G[x][i], x);   }   void adjust(int &u, const int val) {     for (int i = 16; i >= 0; --i)       if (dep[f[u][i]] >= val) u = f[u][i];   }   int lca(int u, int v) {     if (dep[u] > dep[v])       adjust(u, dep[v]);     else if (dep[u] < dep[v])       adjust(v, dep[u]);     if (u == v) return u;     for (int i = 16; i >= 0; --i)       if (f[u][i] ^ f[v][i]) u = f[u][i], v = f[v][i];     return f[u][0];   }   int main() {     n = get(), m = get();     for (int u, v; m--;) {       u = get(), v = get();       add(u, v), add(v, u);     }     for (int i = 1; i <= n; ++i)       if (!dfn[i]) tarjan(i, 0);     for (int i = 1; i <= n; ++i)       for (int j = head[i]; j; j = e[j].nxt)         if (scc[i] ^ scc[e[j].to]) G[scc[i]].push_back(scc[e[j].to]);     dfs(1, 0);     for (int q = get(), u, v, x, k; q--;) {       u = scc[get()], v = scc[get()], x = lca(u, v);       k = w[u] + w[v] - (w[x] << 1) + (siz[x] > 1);       printf( %d n , pow(2, k));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct st {     int t, x, id;   };   const int INF = 1000 * 1000 * 1000;   bool operator<(const st &a, const st &b) {     return a.x < b.x || a.x == b.x && a.t < b.t;   }   int main() {     st st_inf;     st_inf.x = INF;     st_inf.t = INF;     st_inf.id = INF;     int N, M;     queue<st> ost;     cin >> N >> M;     st r;     for (int i = 0; i < N; ++i) {       scanf( %d%d , &r.t, &r.x);       r.id = i;       ost.push(r);     }     int OST = N;     int BUS = 0;     vector<st> bus;     long long int T = 0;     vector<long long int> R(100005);     while (BUS || OST) {       while (OST && BUS < M) {         st t = ost.front();         T = max(T, (long long int)t.t);         bus.push_back(t);         ost.pop();         OST--;         BUS++;       }       sort(bus.begin(), bus.end());       queue<st> w;       int y = 0;       while (y < bus.size() && bus[y].t != INF) {         w.push(bus[y]);         y++;       }       BUS = 0;       int L = 0;       bus.clear();       while (!w.empty()) {         int X;         X = w.front().x;         int cnt_v = 1;         R[w.front().id] = T + (X - L);         w.pop();         while (!w.empty()) {           if (w.front().x == X) {             R[w.front().id] = T + (X - L);             w.pop();             cnt_v++;           } else {             break;           }         }         T += (X - L) + (int)(cnt_v / 2) + 1;         L = X;         if (w.empty()) {           T += L;         }       }     }     for (int i = 0; i < N; ++i) {       cout << R[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long sq(long long k) { return k * k; }   long long knan(long long k, long long n) {     if (n == 1)       return k;     else if (n == 0)       return 1;     else {       if (n % 2 == 0)         return sq(knan(k, n / 2)) % 1000000007;       else         return (k * knan(k, n - 1)) % 1000000007;     }   }   int main() {     string s;     int p[4], n;     for (int i = 0; i < 4; i++) p[i] = 0;     cin >> n;     cin >> s;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  A ) p[0]++;       if (s[i] ==  T ) p[1]++;       if (s[i] ==  C ) p[2]++;       if (s[i] ==  G ) p[3]++;     }     int max(0), brmax(0);     for (int i = 0; i < 4; i++)       if (p[i] > max) max = p[i];     for (int i = 0; i < 4; i++)       if (p[i] == max) brmax++;     cout << knan(brmax, n) % 1000000007 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int n, k;       cin >> n >> k;       long long int a, b, c, d;       cin >> a >> b;       cin >> c >> d;       if (a > c || (a == c && b > d)) {         swap(a, c);         swap(b, d);       }       long long int per = max(0LL, c - b);       long long int capacity = max(b, d) - a;       long long int current = max(0LL, min(b, d) - c);       capacity = capacity - current;       k = max(0LL, k - n * current);       if (k == 0) {         cout << 0 << endl;         continue;       }       long long int ans = 0;       ans += per;       long long int num = min(k, capacity);       ans += num;       k -= num;       n--;       if (k == 0) {         cout << ans << endl;         continue;       }       if (per + capacity >= 2 * capacity) {         ans += 2 * k;       } else {         long long int divi = min(k / capacity, n);         ans += (per + capacity) * (divi);         k -= divi * capacity;         if (divi == n || k >= capacity) {           ans += 2 * k;         } else {           if (k + per < 2 * k)             ans += k + per;           else             ans += 2 * k;         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void rd(T &x) {     char ch;     x = 0;     bool fl = false;     while (!isdigit(ch = getchar())) (ch ==  - ) && (fl = true);     for (x = (ch ^  0 ); isdigit(ch = getchar()); x = x * 10 + (ch ^  0 ))       ;     (fl == true) && (x = -x);   }   template <class T>   inline void ot(T x) {     x / 10 ? ot(x / 10) : putchar(x % 10 +  0 );   }   template <class T>   inline void prt(T a[], int st, int nd) {     for (register int i = st; i <= nd; ++i) printf( %lld  , a[i]);     putchar(  n );   }   namespace Miracle {   const int N = 1e5 + 10;   const int mod = 1e9 + 7;   int n;   long long qm(long long x, long long y) {     long long ret = 1;     while (y) {       if (y & 1) ret = ret * x % mod;       x = x * x % mod;       y >>= 1;     }     return ret;   }   long long jie[N], inv[N];   long long m25[N], i26[N];   int iv;   int exi[N];   int ans[450][N];   int cnt;   long long C(int n, int m) {     if (n < 0 || m < 0 || n < m) return 0;     return jie[n] * inv[m] % mod * inv[n - m] % mod;   }   char s[N];   int main() {     jie[0] = 1;     for (register int i = 1; i <= N - 5; ++i) jie[i] = jie[i - 1] * i % mod;     inv[N - 5] = qm(jie[N - 5], mod - 2);     for (register int i = N - 6; i >= 0; --i) inv[i] = inv[i + 1] * (i + 1) % mod;     int m, t;     iv = qm(26, mod - 2);     m25[0] = 1, i26[0] = 1;     for (register int i = 1; i <= N - 5; ++i)       m25[i] = m25[i - 1] * 25 % mod, i26[i] = i26[i - 1] * iv % mod;     rd(t);     scanf( %s , s + 1);     m = strlen(s + 1);     int op;     while (t--) {       rd(op);       if (op == 1) {         scanf( %s , s + 1);         m = strlen(s + 1);       } else {         rd(n);         if (!exi[m]) {           exi[m] = ++cnt;           for (register int i = m; i <= N - 5; ++i) {             ans[cnt][i] = ((long long)ans[cnt][i - 1] +                            C(i - 1, m - 1) * m25[i - m] % mod * i26[i] % mod) %                           mod;           }         }         long long now = qm(26, n) * ans[exi[m]][n] % mod;         printf( %lld n , now);       }     }     return 0;   }   }  // namespace Miracle   signed main() {     Miracle::main();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, b, m;   int a[100009], sum[100009];   map<int, int> h;   int main() {     cin >> b >> m >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       sum[i] = (sum[i - 1] + a[i]) % (b - 1);     }     long long zero = 0, t = 0;     for (int i = 1; i <= n; i++) {       if (a[i] == 0)         t++;       else {         zero += 1ll * t * (t + 1) / 2;         t = 0;       }     }     if (t) zero += 1ll * t * (t + 1) / 2;     if (m == 0) {       cout << zero << endl;       return 0;     }     long long ans = 0;     h[0]++;     for (int i = 1; i <= n; i++) {       int t = ((sum[i] - m) % (b - 1) + (b - 1)) % (b - 1);       ans += h[t];       h[sum[i]]++;     }     if (m == b - 1) ans -= zero;     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int c(int x) {     int rev = 0;     int tambah = 1;     while (x != 0) {       int temp = x % 10;       if (temp == 4 || temp == 7) {         rev += (tambah * (temp));         tambah *= 10;       }       x /= 10;     }     return rev;   }   int main() {     int a, b;     scanf( %d %d , &a, &b);     a++;     while (c(a) != b) {       a++;     }     printf( %d n , a);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD(1000000007);   const int INF((1 << 30) - 1);   const int MAXN(55);   int a[MAXN];   string b[MAXN];   string gen(int x) {     string ret =   ;     if (x < 26)       ret +=  A ;     else       ret +=  B ;     ret += ( a  + x % 26);     return ret;   }   int main() {     int n, k;     scanf( %d%d , &n, &k);     for (int i = 0; i < n - k + 1; i++) {       string s;       cin >> s;       a[i] = (s ==  YES );     }     int now = 0;     for (int i = 0; i < k; i++) b[i] = gen(now++);     if (a[0] == 0) b[k - 1] = b[0];     for (int i = 1; i <= n - k; i++) {       if (a[i] == 1)         b[i + k - 1] = gen(now++);       else         b[i + k - 1] = b[i];     }     for (int i = 0; i < n; i++) cout << b[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 15;   int k, n, m, x, y, ans;   int dz[6] = {0, 0, 0, 0, 1, -1};   int dx[6] = {0, 0, 1, -1, 0, 0};   int dy[6] = {1, -1, 0, 0, 0, 0};   char plt[N][N][N];   bool mark[N][N][N];   bool isval(int a, int b, int c) {     if (a < k && a >= 0 && b < n && b >= 0 && c < m && c >= 0 &&         plt[a][b][c] ==  . ) {       return true;     }     return false;   }   void dfs(int a, int b, int c) {     mark[a][b][c] = true;     ans++;     for (int i = 0; i < 6; i++) {       if (isval(a + dz[i], b + dx[i], c + dy[i]) &&           !mark[a + dz[i]][b + dx[i]][c + dy[i]]) {         dfs(a + dz[i], b + dx[i], c + dy[i]);       }     }     return;   }   int main() {     cin >> k >> n >> m;     for (int i = 0; i < k; i++) {       for (int j = 0; j < n; j++) {         for (int l = 0; l < m; l++) {           cin >> plt[i][j][l];         }       }     }     cin >> x >> y;     x--;     y--;     dfs(0, x, y);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using vi = vector<int>;   using vvi = vector<vi>;   int main() {     int N;     cin >> N;     vvi tree(N);     for (int i = 0; i < N - 1; ++i) {       int a, b;       cin >> a >> b;       a--;       b--;       tree[a].push_back(b);       tree[b].push_back(a);     }     int min = 0, max = 0;     vi min_v(N), max_v(N);     for (int i = 0; i < N; ++i) min_v[i] = max_v[i] = i;     vi degree(N);     queue<int> q;     for (int u = 0; u < N; ++u)       if ((degree[u] = tree[u].size()) == 1) q.push(u);     while (!q.empty()) {       int u = q.front();       q.pop();       int n = tree[u][0];       for (int v : tree[u])         if (degree[v] > 0) n = v;       if (min_v[u] == u) {         swap(min_v[u], min_v[n]);         min += 2;       }       if (degree[n] > 0) {         degree[u] = 0;         if (--degree[n] == 1) q.push(n);       }     }     cout << min << endl;     for (int u = 0; u < N; ++u) cout << min_v[u] + 1 <<    ;     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   inline void file() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   int main() {     char b[10000];     int a;     cin >> a;     int c = 0;     for (int i = 0; i < a; ++i) {       cin >> b[0] >> b[1] >> b[2];       if (b[0] ==  -  and b[1] ==  -  or b[2] ==  -  and b[1] ==  - )         c--;       else         c++;     }     cout << c;   }
#include <bits/stdc++.h>   using namespace std;   int a[1000005];   int main() {     int t, n;     cin >> t;     while (t--) {       cin >> n;       int g = 0, s = 0, b = 0;       int m = n / 2;       for (int i = 1; i <= n; i++) {         cin >> a[i];       }       int i = 1;       while (a[i] == a[1] && i <= m) {         i++;         g++;       }       int j = i;       while (a[i] == a[j] && i <= m) {         i++;         s++;       }       while (s <= g && i <= m) {         int k = i;         while (a[i] == a[k] && i <= m) {           s++;           i++;         }       }       while (a[i] != a[m + 1] && i <= m) {         b++;         i++;       }       if (g >= s || g >= b) {         cout <<  0 0 0 n ;         continue;       }       cout << g <<     << s <<     << b <<     << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 500;   char s[N];   int son[N][26];   int fail[N], pos[N];   int n, m;   int cnt;   inline void insert(char s[], int n, int id) {     int i, cur = 0;     for (i = 1; i <= n; i++) {       if (!son[cur][s[i] -  a ]) son[cur][s[i] -  a ] = ++cnt;       cur = son[cur][s[i] -  a ];     }     pos[id] = cur;   }   queue<int> Q;   inline void build() {     int i;     for (i = 0; i <= 25; i++)       if (son[0][i]) Q.push(son[0][i]);     while (!Q.empty()) {       int x = Q.front();       Q.pop();       for (i = 0; i <= 25; i++)         if (!son[x][i])           son[x][i] = son[fail[x]][i];         else           fail[son[x][i]] = son[fail[x]][i], Q.push(son[x][i]);     }   }   struct Edge {     int to, nxt;   };   Edge e[N << 1];   int lst[N];   inline void add(int u, int v) {     static int cnt = 0;     e[++cnt] = (Edge){v, lst[u]}, lst[u] = cnt;   }   int dfn[N], low[N];   inline void dfs(int x) {     static int idx = 0;     int i;     dfn[x] = ++idx;     for (i = lst[x]; ~i; i = e[i].nxt) dfs(e[i].to);     low[x] = idx;   }   int C[N];   inline void update(int x, int delta) {     while (x <= cnt + 1) C[x] += delta, x += ((x) & -(x));   }   inline int query(int x) {     int res = 0;     while (x > 0) res += C[x], x -= ((x) & -(x));     return res;   }   int del[N];   int main() {     int i;     scanf( %d%d , &m, &n);     for (i = 1; i <= n; i++) scanf(  %s  , s + 1), insert(s, strlen(s + 1), i);     build();     for (i = 0; i <= cnt; i++) lst[i] = -1;     for (i = 1; i <= cnt; i++) add(fail[i], i);     dfs(0);     for (i = 1; i <= n; i++) update(dfn[pos[i]], 1), update(low[pos[i]] + 1, -1);     while (m--) {       scanf(  %s  , s), n = strlen(s + 1);       if (s[0] ==  ? ) {         int cur = 0, ans = 0;         for (i = 1; i <= n; i++) {           if (!son[cur][s[i] -  a ])             cur = fail[cur];           else             cur = son[cur][s[i] -  a ];           ans += query(dfn[cur]);         }         printf( %d n , ans);       } else {         int id = 0;         for (i = 1; i <= n; i++) id = (id << 1) + (id << 3) + (s[i] ^ 48);         if (s[0] ==  - ) {           if (!del[id])             update(dfn[pos[id]], -1), update(low[pos[id]] + 1, 1), del[id] = 1;         } else if (del[id])           update(dfn[pos[id]], 1), update(low[pos[id]] + 1, -1), del[id] = 0;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string s;     cin >> n;     cin >> s;     if (!(n % 2)) {       for (int i = 0; i < n; ++i) {         cout << s[i];         if (i % 2 && i != n - 1) cout <<  - ;       }     } else {       for (int i = 0; i < n - 3; ++i) {         cout << s[i];         if (i % 2) cout <<  - ;       }       for (int i = n - 3; i < n; ++i) cout << s[i];     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, s, tmp1, tmp2;   vector<long long> ans;   vector<vector<long long>> g(100000);   bool vs[2][100000];   bool vs1[100000] = {0}, rc[100000] = {0};   bool a = false, w = false, d = false, t = false;   long long cnt = 0;   void hasc(long long v) {     vs1[v - 1] = true;     rc[v - 1] = true;     for (auto el : g[v - 1]) {       if (!vs1[el - 1])         hasc(el);       else if (rc[el - 1]) {         d = true;       }     }     rc[v - 1] = false;   }   void dfs(long long v) {     ans.push_back(v);     vs[a][v - 1] = true;     if (a && !(g[v - 1].size())) {       w = 1;       return;     }     a = !a;     for (auto el : g[v - 1])       if (!vs[a][el - 1] && !w) {         dfs(el);       }     a = !a;     if (w) return;     ans.pop_back();   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> tmp1;       for (int j = 0; j < tmp1; j++) {         cin >> tmp2;         g[i].push_back(tmp2);       }     }     cin >> s;     dfs(s);     hasc(s);     if (w) {       cout <<  Win  << endl;       for (auto el : ans) cout << el <<    ;       cout << endl;     } else if (d) {       cout <<  Draw  << endl;     } else       cout <<  Lose  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<pair<int, int> > > Adj;   vector<int> Col;   bool DFS(int u, int f) {     Col[u] = 1 + f;     bool pos = 0;     for (auto i : Adj[u]) {       if (Col[i.first]) {         if ((f ^ i.second) == Col[i.first] - 1)           continue;         else           return 1;       }       pos |= DFS(i.first, f ^ i.second);     }     return pos;   }   template <typename T>   T fast_exp(T base, T power, T M = 0) {     if (M) base %= M;     T result = 1;     while (power) {       if (power & 1) result *= base;       power >>= 1;       base *= base;       if (M) {         base %= M;         result %= M;       }     }     return result;   }   long long Calc(string S, int lA, int lB) {     Adj.clear();     Col.clear();     Adj.resize(lA + lB + 1);     Col.resize(lA + lB + 1);     for (int x = 0; x < lA; x++) {       Adj[x].push_back({lA - x - 1, 0});       Adj[lA - x - 1].push_back({x, 0});     }     for (int x = 0; x < lB; x++) {       Adj[lA + x].push_back({lA + lB - x - 1, 0});       Adj[lA + x].push_back({lA + lB - x - 1, 0});     }     for (int x = 0; x < lA; x++) {       if (S[x] ==  ? ) continue;       if (x < lA - lB) {         Adj[x].push_back({lA + lB, S[x] -  0 });         Adj[lA + lB].push_back({x, S[x] -  0 });       } else {         Adj[x].push_back({lB + x, S[x] -  0 });         Adj[lB + x].push_back({x, S[x] -  0 });       }     }     Adj[lA + lB].push_back({lA, 1});     Adj[lA].push_back({lA + lB, 1});     int cnt = 0;     for (int x = 0; x < lA + lB + 1; x++) {       if (Col[x]) continue;       if (DFS(x, 0)) return 0;       cnt++;     }     return fast_exp<long long>(2, cnt - 1, 998244353);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     string S;     cin >> S;     long long ans = 0;     int lA = S.size();     for (int lB = 1; lB < lA; lB++) {       ans += Calc(S, lA, lB);       ans %= 998244353;     }     cout << ans << endl;     return 0;   }