malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[201];     for (int i = 1; i <= n; ++i) cin >> arr[i];     int brr[201] = {0}, count = 0;     for (int i = 1; i <= n; ++i) {       if (i == 1 && n >= 2) {         if (arr[1] == 1 && arr[2] == 2) brr[i] = 1;       } else {         if (i == n && n >= 2) {           if (arr[n] == 1000 && arr[n - 1] == 999) brr[i] = 1;         } else {           if (arr[i - 1] == arr[i] - 1 && arr[i + 1] == arr[i] + 1) brr[i] = 1;         }       }     }     int t = 0;     for (int i = 1; i <= n;) {       while (i <= n && brr[i] == 1) {         t++;         i++;       }       while (i <= n && brr[i] == 0) {         i++;       }       count = max(count, t);       t = 0;     }     cout << count << endl;   }
#include <bits/stdc++.h>   using namespace std;   double esp = 1e-11;   const double PI = acos(-1.0);   const long long int INF = 0x3f3f3f3f;   const long long int MOD = 1e9 + 7;   const int maxn = 200010;   int main() {     int a, b, c;     scanf( %d%d%d , &a, &b, &c);     long double x = (-b + sqrt((long double)b * b - 4 * a * c)) / (2 * a);     long double y = (-b - sqrt((long double)b * b - 4 * a * c)) / (2 * a);     if (x < y) swap(x, y);     printf( %.6f n%.6f n , (double)x, (double)y);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const int NMAX = 300010;   const double E = 1e-8;   const double PI = acos(-1);   int n, m, stest;   int d;   set<long long> St;   long long st[NMAX], h[NMAX];   pair<int, int> Tree[4 * NMAX];   int dp[NMAX], trace[NMAX];   pair<int, int> cmp(pair<int, int> a, pair<int, int> b) {     if (a.first > b.first)       return a;     else       return b;   }   void update(int i, int lo, int hi, int u, int x, int vt) {     if (lo == hi) {       Tree[i] = cmp(Tree[i], pair<int, int>(x, vt));       return;     }     int mid = (lo + hi) >> 1;     if (u <= mid)       update(2 * i, lo, mid, u, x, vt);     else       update(2 * i + 1, mid + 1, hi, u, x, vt);     Tree[i] = cmp(Tree[2 * i], Tree[2 * i + 1]);   }   pair<int, int> query(int i, int lo, int hi, int u, int v) {     if (v < lo || hi < u) return pair<int, int>(0, 0);     if (u <= lo && hi <= v) return Tree[i];     int mid = (lo + hi) >> 1;     return cmp(query(2 * i, lo, mid, u, v), query(2 * i + 1, mid + 1, hi, u, v));   }   void truy(int x) {     if (x == 0) return;     truy(trace[x]);     cout << x <<    ;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> d;     for (int i = 1; i <= n; i++) {       cin >> h[i];       St.insert(h[i]);       St.insert(h[i] - d);       St.insert(h[i] + d);     }     for (set<long long>::iterator it = St.begin(); it != St.end(); it++)       st[++m] = *it;     int ans = 0, vt = 0;     for (int i = 1; i <= n; i++) {       int pos = lower_bound(st + 1, st + m + 1, h[i]) - st;       int u = lower_bound(st + 1, st + m + 1, h[i] - d) - st;       int v = lower_bound(st + 1, st + m + 1, h[i] + d) - st;       pair<int, int> res = cmp(query(1, 1, m, 1, u), query(1, 1, m, v, m));       dp[i] = res.first + 1;       trace[i] = res.second;       update(1, 1, m, pos, dp[i], i);       if (dp[i] > ans) {         ans = dp[i];         vt = i;       }     }     cout << ans << endl;     truy(vt);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int MXN = 3e5 + 5;   const int MOD = 998244353;   const int LOG = 19;   int add(int x, int y) { return (x += y) < MOD ? x : x - MOD; }   int sub(int x, int y) { return (x -= y) >= 00 ? x : x + MOD; }   int mul(int x, int y) { return (ll)x * y % MOD; }   int pwr(int x, int p) {     if (p == 0) return 1;     if (p % 2) return mul(x, pwr(x, p - 1));     return pwr(mul(x, x), p / 2);   }   int inv(int x) { return pwr(x, MOD - 2); }   int sol = 1;   int ok[MXN];   int val[MXN];   int dep[MXN];   int lca[MXN];   int nxt[MXN];   int dp[MXN][2];   int anc[MXN][LOG];   vector<int> adj[MXN];   int getlca(int x, int y) {     if (dep[x] < dep[y]) swap(x, y);     int diff = dep[x] - dep[y];     for (int i = 0; i < LOG; ++i) {       if (diff >> i & 1) x = anc[x][i];     }     if (x == y) return x;     for (int i = LOG - 1; i >= 0; --i) {       if (anc[x][i] != anc[y][i]) {         x = anc[x][i];         y = anc[y][i];       }     }     return anc[x][0];   }   void dfs1(int x, int p) {     if (val[x]) {       if (lca[val[x]]) {         lca[val[x]] = getlca(lca[val[x]], x);       } else {         lca[val[x]] = x;       }     }     for (int y : adj[x]) {       if (y == p) continue;       anc[y][0] = x;       dep[y] = dep[x] + 1;       for (int i = 0; i < LOG - 1; ++i) {         anc[y][i + 1] = anc[anc[y][i]][i];       }       dfs1(y, x);     }   }   void dfs2(int x, int p) {     vector<int> vec;     for (int y : adj[x]) {       if (y == p) continue;       dfs2(y, x);       if (ok[y]) {         ok[x] = 1;         vec.push_back(y);       }       if (val[y] && y != lca[val[y]]) {         if (val[x] && val[x] != val[y]) {           cout <<  0 n ;           exit(0);         }         val[x] = val[y];       }     }     if (val[x]) {       dp[x][0] = ok[x] = 1;       for (int y : vec) {         sol = mul(sol, add(mul(dp[y][0], nxt[y] + 1), dp[y][1]));       }     } else if (vec.size() > 1) {       dp[x][1] = 1;       for (int y : vec) {         int tmp = add(dp[y][1], mul(dp[y][0], nxt[y] + 1));         dp[x][1] = mul(dp[x][1], tmp);       }       for (int y : vec) {         int tmp = add(dp[y][1], mul(dp[y][0], nxt[y] + 1));         dp[x][0] = add(dp[x][0], mul(mul(dp[x][1], inv(tmp)), dp[y][0]));       }     } else if (vec.size() == 1) {       dp[x][0] = dp[vec[0]][0];       dp[x][1] = dp[vec[0]][1];       nxt[x] = nxt[vec[0]] + 1;     }   }   int main() {     ios::sync_with_stdio(0), cin.tie(0);     int n, k;     cin >> n >> k;     for (int i = 1; i <= n; ++i) {       cin >> val[i];     }     for (int i = 2; i <= n; ++i) {       int x, y;       cin >> x >> y;       adj[x].push_back(y);       adj[y].push_back(x);     }     dfs1(1, 0);     dfs2(1, 0);     if (dp[1][0]) sol = mul(sol, dp[1][0]);     cout << sol <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int l[100000 + 9], r[100000 + 9];   int n, p;   int main() {     cin >> n >> p;     for (int i = 0; i < n; i++) {       cin >> l[i] >> r[i];     }     double ans = 0;     for (int i = 0; i < n; i++) {       int j = (i + 1) % n;       int div1 = r[i] / p - (l[i] - 1) / p;       int nondiv1 = r[i] - l[i] + 1 - div1;       int div2 = r[j] / p - (l[j] - 1) / p;       int nondiv2 = r[j] - l[j] + 1 - div2;       double nondivs = 1.0 - ((double)nondiv1 / double(r[i] - l[i] + 1)) *                                  ((double)nondiv2 / double(r[j] - l[j] + 1));       ans += nondivs * 2000.0;     }     cout << fixed << setprecision(15) << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char *argv[]) {     ios::sync_with_stdio(false);     cin.tie(nullptr);     string s, t;     cin >> s >> t;     int ns = s.size() - 1;     int nt = t.size() - 1;     bool stop = true;     while (stop && (ns >= 0 && nt >= 0)) {       if (s[ns] != t[nt]) {         stop = false;       }       if (stop) {         ns--;         nt--;       }     }     int r = ns + nt + 2;     cout << r;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxm = 3e5 + 5;   const long long mod = 998244353;   long long fac[maxm], inv[maxm];   long long l[maxm], r[maxm];   pair<long long, long long> p[25];   long long sum[maxm][45];   long long num[maxm];   long long n, m;   long long ppow(long long a, long long b, long long mod) {     long long ans = 1 % mod;     a %= mod;     while (b) {       if (b & 1) ans = ans * a % mod;       a = a * a % mod;       b >>= 1;     }     return ans;   }   void init() {     fac[0] = 1;     for (long long i = 1; i < maxm; i++) fac[i] = fac[i - 1] * i % mod;     inv[maxm - 1] = ppow(fac[maxm - 1], mod - 2, mod);     for (long long i = maxm - 2; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % mod;   }   long long cal(long long x) {     long long ans = 0;     while (x) {       ans++;       x &= (x - 1);     }     return ans;   }   long long C(long long n, long long m) {     if (m < 0 || m > n) return 0;     return fac[n] * inv[m] % mod * inv[n - m] % mod;   }   signed main() {     ios::sync_with_stdio(0);     init();     cin >> n >> m;     for (long long i = 1; i <= n; i++) {       cin >> l[i] >> r[i];     }     for (long long i = 0; i < m; i++) {       cin >> p[i].first >> p[i].second;     }     for (long long i = 1; i <= n; i++) {       num[l[i]]++;       num[r[i] + 1]--;     }     for (long long i = 1; i <= n; i++) {       num[i] += num[i - 1];     }     for (long long i = 1; i <= n; i++) {       for (long long j = 0; j <= m * 2; j++) {         sum[i][j] = (sum[i - 1][j] + C(num[i] - j, i - j)) % mod;       }     }     long long ans = 0;     for (long long i = 0; i < (1 << m); i++) {       set<long long> s;       for (long long j = 0; j < m; j++) {         if (i >> j & 1) {           s.insert(p[j].first);           s.insert(p[j].second);         }       }       long long tot = s.size();       long long L = 1, R = n;       for (auto x : s) {         L = max(L, l[x]);         R = min(R, r[x]);       }       if (L > R) continue;       long long t = (sum[R][tot] - sum[L - 1][tot] + mod) % mod;       if (cal(i) & 1) {         ans = (ans - t + mod) % mod;       } else {         ans = (ans + t) % mod;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5, R = 1e4;   int n, l[N], r[N];   long long cnt[R + 1];   double all;   bool used[N];   long long f(int cur, int c, int mn, int x = N) {     if (cur == n) {       if (mn > 0) {         return 0;       }       long long cnt = 1;       for (int i = 0; i < n; i++) {         if (!used[i] && i != x) {           cnt *= max(0, min(c, r[i] + 1) - l[i]);         }       }       return cnt;     }     long long cnt = f(cur + 1, c, mn, x);     if (cur != x && l[cur] <= c && c <= r[cur]) {       used[cur] = true;       cnt += f(cur + 1, c, mn - 1, x);       used[cur] = false;     }     return cnt;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d%d , l + i, r + i);     }     for (int cur = 0; cur <= R; cur++) {       long long sum = 0;       for (int i = 0; i < n; i++) {         sum += f(0, cur, 1, i) * max(0, r[i] - max(cur, l[i] - 1));       }       sum += f(0, cur, 2);       all += sum;       cnt[cur] = sum;     }     double ans = 0;     for (int i = 0; i <= R; i++) {       ans += cnt[i] / all * i;     }     printf( %.10f , ans);   }
#include <bits/stdc++.h>   using namespace std;   int i, n, k, x, ans, c;   pair<int, int> a[100005];   int main() {     cin >> n >> k;     for (i = 0; i < n; i++) {       cin >> x;       a[i].first = 10 - x % 10;       a[i].second = x;     }     sort(a, a + n);     for (i = 0; i < n; i++) {       if (a[i].second < 100 && (k - (10 - a[i].second % 10) >= 0)) {         a[i].second += 10 - a[i].second % 10;         k -= a[i].first;       } else {         break;       }       if (i == n - 1) {         break;       }     }     for (i = 0; i < n; i++) {       ans += a[i].second / 10;     }     cout << min(n * 10, ans + k / 10);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, h;     cin >> n >> m >> h;     int f[m];     int l[n];     int t[n][m];     int ans[n][m];     for (int i = 0; i < m; i++) cin >> f[i];     for (int i = 0; i < n; i++) cin >> l[i];     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         cin >> t[i][j];         if (t[i][j] == 1) {           ans[i][j] = 1;         }       }     memset(ans, 0, sizeof(ans));     for (int i = 0; i < m; i++) {       int h1 = f[i];       for (int j = 0; j < n; j++) {         if (t[j][i] == 1 && l[j] >= h1) {           ans[j][i] = h1;         }       }     }     for (int i = 0; i < n; i++) {       int h1 = l[i];       for (int j = 0; j < m; j++) {         if (t[i][j] == 1 && f[j] >= h1) {           ans[i][j] = h1;         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cout << ans[i][j] <<    ;       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, now, t, mx, gcd, m, a[107];     scanf( %d , &n);     for (i = 0; i ^ n; i++) {       scanf( %d , a + i);     }     sort(a, a + n);     mx = gcd = a[0];     m = 1;     for (i = 1; i ^ n; i++) {       if (a[i - 1] != a[i]) {         mx = mx < a[i] ? a[i] : mx;         m++;         now = a[i];         while (gcd) {           t = now;           now = gcd;           gcd = t % gcd;         }         gcd = now;       }     }     mx /= gcd;     mx -= m;     printf(mx & 1 ?  Alice n  :  Bob n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100009];   int b[100009];   int main() {     int n;     cin >> n;     map<int, int> mp;     for (int i = 0; i < n; i++) {       cin >> a[i];       mp[a[i]]++;     }     for (int j = 0; j < n; j++) {       cin >> b[j];       mp[b[j]]++;     }     int c = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (mp.find(a[i] xor b[j]) != mp.end()) c++;       }     }     if (c & 1) {       cout <<  Koyomi n ;     } else {       cout <<  Karen n ;     }   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     int n;     cin >> n;     int ar[n];     for (int i = 0; i < n; i++) cin >> ar[i];     int max_n = pow(2, n);     bool ans = false;     for (int i = 0; i < max_n; i++) {       int temp = i;       int val = 0;       for (int j = 0; j < n; j++) {         if (temp & 1) {           val = (val + ar[j]) % 360;         } else {           val = (val - ar[j] + 360) % 360;         }         temp = temp >> 1;       }       if (val == 0) {         ans = true;         break;       }     }     if (ans) {       cout <<  YES n ;     } else {       cout <<  NO n ;     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   const int INF = 0x3f3f3f3f;   const int GRAPH_SIZE = 20010;   int pin[GRAPH_SIZE], dep[GRAPH_SIZE], s = 0, t = GRAPH_SIZE - 1;   struct EDGE {     int u, v, c;   };   vector<EDGE> e;   vector<int> each[GRAPH_SIZE];   bool bfs() {     queue<int> Q;     Q.push(s);     while (!Q.empty()) {       int now = Q.front();       Q.pop();       for (auto it : each[now]) {         int next = e[it].v;         if (e[it].c)           if (dep[next] > dep[now] + 1) {             dep[next] = dep[now] + 1;             Q.push(next);           }       }     }     return dep[t] != INF;   }   int dfs(int now, int flow) {     if (now == t) {       return flow;     }     for (int& i = pin[now]; i < each[now].size(); i++) {       int it = each[now][i];       if (e[it].c && dep[e[it].v] == dep[now] + 1) {         int tmp;         if (tmp = dfs(e[it].v, min(flow, e[it].c))) {           e[it].c -= tmp;           e[it ^ 1].c += tmp;           return tmp;         }       }     }     return 0;   }   int Dinic() {     int max_flow = 0;     for (int i = 0; i < GRAPH_SIZE; ++i) {       dep[i] = INF;     }     dep[s] = 0;     while (bfs()) {       for (int i = 0; i < GRAPH_SIZE; ++i) {         pin[i] = 0;       }       int tmp;       while (tmp = dfs(s, INF)) {         max_flow += tmp;       }       for (int i = 0; i < GRAPH_SIZE; ++i) {         dep[i] = INF;       }       dep[s] = 0;     }     return max_flow;   }   void make_edge(int U, int V, int C) {     EDGE tmp;     tmp.u = U;     tmp.v = V;     tmp.c = C;     e.push_back(tmp);     each[U].push_back(e.size() - 1);     swap(tmp.u, tmp.v);     tmp.c = 0;     e.push_back(tmp);     each[V].push_back(e.size() - 1);   }   void init() {     e.clear();     for (int i = 0; i < GRAPH_SIZE; ++i) {       each[i].clear();     }   }   vector<pair<int, pair<int, int> > > edges;   int n;   int m;   bool check(int x) {     init();     for (int i = 1; i <= n; ++i) make_edge(s, i, 1);     for (int i = 1; i <= n; ++i) make_edge(i + n, t, 1);     for (int i = 0; i < x; ++i) {       make_edge(edges[i].second.first, edges[i].second.second + n, 1);     }     if (Dinic() == n) return true;     return false;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 1; i <= m; ++i) {       int u, v, d;       cin >> u >> v >> d;       edges.push_back(make_pair(d, make_pair(u, v)));     }     sort(edges.begin(), edges.end());     if (!check(m)) {       cout << -1 << endl;       return 0;     }     int l = 1, r = m;     while (l < r) {       int mid = (l + r) >> 1;       if (check(mid)) {         r = mid;       } else {         l = mid + 1;       }     }     cout << edges[l - 1].first << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, i, j, x1, x2, y1, y2;     cin >> n;     vector<string> a(n);     for (i = 0; i < n; i++) cin >> a[i];     x1 = 0;     y1 = 0;     while (a[x1][y1] ==  0  && (x1 <= n - 1 || y1 < n - 1))       if (y1 == n - 1) {         y1 = 0;         x1++;       } else         y1++;     x2 = n - 1;     y2 = n - 1;     while (a[x2][y2] ==  0  && (x2 > 0 || y2 > 0))       if (y2 == 0) {         y2 = n - 1;         x2--;       } else         y2--;     bool f = true;     if (x1 > x2 || y1 > y2) f = false;     if (a[x1][y1] !=  1 ) f = false;     if (a[x1][y2] !=  1 ) f = false;     if (a[x2][y1] !=  1 ) f = false;     if (a[x2][y2] !=  1 ) f = false;     for (i = y1 + 1; i < y2; i++)       if (a[x1][i] !=  2  || a[x2][i] !=  2 ) f = false;     for (i = x1 + 1; i < x2; i++)       if (a[i][y1] !=  2  || a[i][y2] !=  2 ) f = false;     for (i = x1 + 1; i < x2; i++)       for (j = y1 + 1; j < y2; j++)         if (a[i][j] !=  4 ) f = false;     for (i = 0; i < x1; i++)       for (j = 0; j < n; j++)         if (a[i][j] !=  0 ) f = false;     for (i = x2 + 1; i < n; i++)       for (j = 0; j < n; j++)         if (a[i][j] !=  0 ) f = false;     for (i = 0; i < n; i++)       for (j = 0; j < y1; j++)         if (a[i][j] !=  0 ) f = false;     for (i = 0; i < n; i++)       for (j = y2 + 1; j < n; j++)         if (a[i][j] !=  0 ) f = false;     if (f)       cout <<  Yes  << endl;     else       cout <<  No  << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int tt = 1;     cin >> tt;     for (int tc = 1; tc <= tt; tc++) {       int a;       cin >> a;       if (360 % (180 - a))         cout <<  NO n ;       else         cout <<  YES n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   long long dp[57 + 7][57 + 7];   long long mdp[57 + 7][57 + 7];   bool vis[57 + 7][57 + 7];   int n, K;   long long ncr[57 + 7][57 + 7];   int L, R;   long long func(int l, int r, int i, int j, int k, int m) {     long long ret = (ncr[l][i] * ncr[r][j]) % mod;     ret = (ret * ncr[L - l + i][k]) % mod;     ret = (ret * ncr[R - r + j][m]) % mod;     return ret;   }   void back(int l, int r) {     if (vis[l][r]) return;     mdp[l][r] = 200000007;     dp[l][r] = 0;     vis[l][r] = true;     if (l == 0 && r == 0) {       mdp[l][r] = 0;       dp[l][r] = 1;       return;     }     if (l * 50 + r * 100 <= K) {       mdp[l][r] = 1;       dp[l][r] = 1;       return;     }     for (int i = 0; i <= l && i * 50 <= K; i++) {       for (int j = 0; j <= r; j++) {         if (i == 0 && j == 0) continue;         if (i * 50 + j * 100 > K) break;         for (int k = 0; k <= L - l + i; k++) {           for (int m = 0; m <= R - r + j; m++) {             if (k * 50 + m * 100 == 0) continue;             if (k * 50 + m * 100 > K) break;             if (l * 50 + r * 100 <= (l - i + k) * 50 + (r - j + m) * 100)               continue;             back(l - (i - k), r - (j - m));             mdp[l][r] = min(mdp[l][r], mdp[l - i + k][r - j + m] + 2);           }         }       }     }     for (int i = 0; i <= l && i * 50 <= K; i++) {       for (int j = 0; j <= r; j++) {         if (i == 0 && j == 0) continue;         if (i * 50 + j * 100 > K) break;         for (int k = 0; k <= L - l + i; k++) {           for (int m = 0; m <= R - r + j; m++) {             if (k * 50 + m * 100 == 0) continue;             if (k * 50 + m * 100 > K) break;             if (l * 50 + r * 100 <= (l - i + k) * 50 + (r - j + m) * 100)               continue;             if (mdp[l - i + k][r - j + m] + 2 == mdp[l][r]) {               dp[l][r] +=                   (func(l, r, i, j, k, m) * dp[l - i + k][r - j + m]) % mod;               dp[l][r] %= mod;             }           }         }       }     }   }   int main() {     ncr[0][0] = 1;     for (int i = 1; i <= 57; i++) {       ncr[i][0] = 1;       ncr[i][i] = 1;       ncr[i][1] = i;     }     for (int i = 2; i <= 57; i++) {       for (int j = 2; j < i; j++) {         ncr[i][j] = (ncr[i - 1][j - 1] + ncr[i - 1][j]) % mod;       }     }     scanf( %d%d , &n, &K);     int l = 0;     int r = 0;     for (int i = 1; i <= n; i++) {       int v;       scanf( %d , &v);       if (v == 50)         l++;       else         r++;     }     L = l;     R = r;     back(l, r);     if (mdp[l][r] != 200000007) {       printf( %d n , (int)mdp[l][r]);       printf( %d n , (int)dp[l][r]);     } else {       printf( -1 n0 n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 410, MOD = 10007;   char s[maxn];   int n, m, mat_s;   typedef long long Mat[maxn][maxn];   void print(Mat A) {     for (int i = 0; i < (mat_s); i++) {       for (int j = 0; j < (mat_s); j++) {         cout << A[i][j] <<    ;       }       cout << endl;     }     cout << endl;   }   void mat_mul(Mat A, Mat B, Mat res) {     static Mat C;     memset(C, 0, sizeof(C));     for (int i = 0; i < (mat_s); i++)       for (int k = (i); k <= (mat_s - 1); k++)         for (int j = (k); j <= (mat_s - 1); j++) {           C[i][j] += A[i][k] * B[k][j];         }     for (int i = 0; i < (mat_s); i++)       for (int j = 0; j < (mat_s); j++) {         C[i][j] %= MOD;       }     memcpy(res, C, sizeof(C));   }   void mat_pow(Mat A, long long k, Mat res) {     static Mat a, r;     memcpy(a, A, sizeof(a));     memset(r, 0, sizeof(r));     for (int i = 0; i < (mat_s); i++) r[i][i] = 1;     while (k) {       if (k & 1) {         mat_mul(r, a, r);       }       if (!(k >>= 1)) {         break;       }       mat_mul(a, a, a);     }     memcpy(res, r, sizeof(r));   }   int dp[210][210][210];   int rec(int l, int r, int n24) {     int& res = dp[l][r][n24];     if (~res) {       return res;     }     if (l == r) {       return res = !n24;     }     if (s[l] == s[r]) {       if (l + 1 == r) {         return res = !n24;       }       return res = rec(l + 1, r - 1, n24);     } else {       if (n24 > 0) {         return res = (rec(l + 1, r, n24 - 1) + rec(l, r - 1, n24 - 1)) % MOD;       } else {         return res = 0;       }     }   }   int n24, n25, n26, times;   int mat_at(Mat A, int c24, int c25) {     int i24 = n24 - c24;     int i25 = n24 + c25 - 1;     int i26 = i25 + n25;     return A[i24][i26];   }   int main() {     scanf( %s%d , s, &n);     m = strlen(s);     n += m;     times = (n + 1) >> 1;     n24 = m - 1;     n26 = n25 = (m + 1) >> 1;     mat_s = n24 + n25 + n26;     static Mat A, B;     for (int i = 0; i < (mat_s); i++) {       if (i < n24) {         A[i][i] = 24;         A[i][i + 1] = 1;       } else if (i < n24 + n25) {         A[i][i] = 25;         if (i + 1 < n24 + n25) {           A[i][i + 1] = 1;         }         A[i][i + n25] = 1;       } else {         A[i][i] = 26;       }     }     mat_pow(A, times - 1, B);     mat_mul(B, A, A);     int ans = 0;     memset(dp, -1, sizeof(dp));     for (int c24 = 0; c24 < (m); c24++) {       int c25 = (m - c24 + 1) >> 1;       if (times - c24 - c25 < 0) {         continue;       }       int ways = rec(0, m - 1, c24);       ans = (ans + ways * mat_at(A, c24, c25)) % MOD;       if ((n & 1) && (!((m - c24) & 1))) {         ans = (ans + MOD - ways * B[n24 - c24][n24 + c25 - 1] % MOD) % MOD;       }     }     printf( %d n , ans);     return 0;   }