malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <typename T>   ostream& operator<<(ostream& s, vector<T> const& v) {     s <<  { ;     for (int i = 0; i < int(v.size()); i++) s << (i ?  ,  :   ) << v[i];     return s <<  } ;   }   template <typename S, typename T>   ostream& operator<<(ostream& s, pair<S, T> const& p) {     return s <<  (  << p.first <<  ,  << p.second <<  ) ;   }   constexpr int MAXN = 100005;   long long minSum(long long n, long long b, long long init, long long l) {     if (b == 1) return ((n + 1) * (n + 2)) / 2 - 1;     long long rem = n, clev = init, ans = 0;     while (rem > 0) {       long long use = min(rem, clev);       rem -= use;       ans += l * use;       clev *= b;       ++l;     }     return ans;   }   bool sv() {     long long N, S;     scanf( %lld%lld , &N, &S);     long long maxBr = 1;     while (maxBr < N && 1 + minSum(N - 1, maxBr, maxBr, 2) > S) ++maxBr;     if (maxBr == N) return false;     long long remN = N - 1, remS = S - 1, curlev = 2, plev = 1;     vector<long long> layers;     while (remN > 0) {       long long a = 0, b = plev * maxBr;       while (b - a > 1) {         long long c = (a + b) / 2;         if (minSum(remN, maxBr, c, curlev) > remS)           a = c;         else           b = c;       }       layers.push_back(b);       remN -= b;       remS -= curlev * b;       ++curlev;       plev = b;     }     if (remS) return false;     vector<int> ans(N);     long long cur = 1;     for (int i = 0; i < int(layers.size()); i++) {       long long pLayer = i ? layers[i - 1] : 1;       long long oldCur = cur;       long long rem = layers[i];       for (int j = oldCur - pLayer; j < int(oldCur); j++) {         for (int k = 0; k < int(maxBr); k++) {           if (rem > 0) {             ans[cur] = j;             --rem;             ++cur;           } else {             goto dn;           }         }       }     dn:;     }     puts( Yes );     for (int i = 1; i < int(N); i++)       printf( %d%c , ans[i] + 1, i == N - 1 ?   n  :    );     return true;   }   int main() {     if (!sv()) puts( No );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s1;     cin >> s1;     for (int i = 0; i < s1.size() - 1; i++) {       while ((s1[i] ==  a  || s1[i] ==  o  || s1[i] ==  y  || s1[i] ==  e  ||               s1[i] ==  u  || s1[i] ==  i ) &&              (s1[i + 1] ==  a  || s1[i + 1] ==  o  || s1[i + 1] ==  y  ||               s1[i + 1] ==  e  || s1[i + 1] ==  u  || s1[i + 1] ==  i )) {         s1.erase(i + 1, 1);       }     }     cout << s1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 3;   int n, l;   double ans, a[N];   int main() {     scanf( %d %d , &n, &l);     for (int i = 0; i < n; ++i) scanf( %lf , a + i);     sort(a, a + n);     if (a[0] != 0) ans = a[0];     if (a[n - 1] != l) ans = max(ans, l - a[n - 1]);     for (int i = 0; i < n - 1; ++i) {       ans = max(ans, (a[i + 1] - a[i]) / 2);     }     printf( %.10lf n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int CC;   long long f[109];   int v[109];   long long d0[109], d1[109];   int main() {     f[1] = 1;     f[2] = 2;     CC = 2;     while (f[CC - 1] + f[CC] < 1000 * 1000 * 1000LL * 1000LL * 1000 * 1000) {       f[CC + 1] = f[CC] + f[CC - 1];       CC++;     }     int T;     for (scanf( %d , &T); T > 0; T--) {       long long n;       scanf( %lld , &n);       memset(v, 0, sizeof v);       int cnt = 0;       for (int i = CC; i > 0 && n > 0; i--) {         if (n - f[i] >= 0) n -= f[i], v[++cnt] = i;       }       reverse(v + 1, v + cnt + 1);       d0[0] = 1, d1[0] = 0;       for (int k = 1; k <= cnt; k++) {         d0[k] = d0[k - 1] + d1[k - 1];         d1[k] = 0;         d1[k] += d0[k - 1] * ((v[k] - v[k - 1] - 1) / 2);         d1[k] += d1[k - 1] * ((v[k] - v[k - 1]) / 2);       }       printf( %lld n , d1[cnt] + d0[cnt]);     }     return 0;   }
#include <bits/stdc++.h>   int main() {     char str[100], i, a;     scanf( %s , str);     a = strlen(str);     if (a % 2 == 0) {       printf( %c , str[(a - 1) / 2]);       for (i = 1; i < ((a - 1) / 2) + 1; i++) {         printf( %c , str[((a - 1) / 2) + i]);         printf( %c , str[((a - 1) / 2) - i]);       }       printf( %c , str[a - 1]);     } else {       printf( %c , str[a / 2]);       for (i = 1; i < (a / 2) + 1; i++) {         printf( %c , str[(a / 2) + i]);         printf( %c , str[(a / 2) - i]);       }     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   const int MOD = 1e9 + 7;   const int MAXN = 1e6 + 5;   const double eps = 1e-14;   int a[MAXN];   void solve() {     int n;     cin >> n;     for (int i = 1; i <= 9; i++) {       cin >> a[i];     }     int mn = a[1], ciph = 1;     for (int i = 2; i <= 9; i++) {       if (a[i] <= mn) {         mn = min(mn, a[i]);         ciph = i;       }     }     char c = ciph +  0 ;     int q = n / mn;     int r = n % mn;     string s =   ;     for (int i = 0; i < q; i++) s += c;     for (int i = 0; i < q; i++) {       for (int j = 9; j >= 1; j--) {         if (r >= a[j] - mn) {           r -= (a[j] - mn);           s[i] = j +  0 ;           break;         }       }     }     if (s.empty())       cout << -1;     else       cout << s;   }   int main() {     if (!1) {       freopen(            474             .in ,            r , stdin);       freopen(            474             .out ,            w , stdout);     }     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = (228 & 322) >> 6;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     double x1, y1, x2, y2;     cin >> x1 >> y1 >> x2 >> y2;     double vmax, t0, vx, vy, wx, wy;     cin >> vmax >> t0 >> vx >> vy >> wx >> wy;     double dx = (x2 - x1);     double dy = (y2 - y1);     double l = 0, r = 1e16;     double ans = 1e16;     for (int i = 0; i < 200; i++) {       double t = (l + r) / 2;       double xx = vx * (t0 < t ? t0 : t);       double yy = vy * (t0 < t ? t0 : t);       if (t > t0) {         xx += wx * (t - t0);         yy += wy * (t - t0);       }       if ((xx - dx) * (xx - dx) + (yy - dy) * (yy - dy) > vmax * vmax * t * t)         l = t;       else {         r = t;         ans = t;       }     }     printf( %.12f n , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1e5 + 10, MOD = 1e9 + 7;   int n, x[MAX_N], y[MAX_N], ordered_x[MAX_N], ordered_y[MAX_N], x_n, y_n,       ans = 1;   int fa[MAX_N * 2], node_cnt[MAX_N * 2], edge_cnt[MAX_N * 2];   void init() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &x[i], &y[i]);       ordered_x[i] = x[i];       ordered_y[i] = y[i];     }     sort(ordered_x + 1, ordered_x + n + 1);     x_n = unique(ordered_x + 1, ordered_x + n + 1) - ordered_x - 1;     for (int i = 1; i <= n; i++)       x[i] = lower_bound(ordered_x + 1, ordered_x + x_n + 1, x[i]) - ordered_x;     sort(ordered_y + 1, ordered_y + n + 1);     y_n = unique(ordered_y + 1, ordered_y + n + 1) - ordered_y - 1;     for (int i = 1; i <= n; i++)       y[i] = lower_bound(ordered_y + 1, ordered_y + y_n + 1, y[i]) - ordered_y;     for (int i = 1; i <= x_n + y_n; i++) fa[i] = i;   }   int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }   void merge(int a, int b) { fa[find(a)] = find(b); }   void solve() {     for (int i = 1; i <= n; i++) merge(x[i], x_n + y[i]);     for (int i = 1; i <= x_n; i++) node_cnt[find(i)]++;     for (int i = 1; i <= y_n; i++) node_cnt[find(x_n + i)]++;     for (int i = 1; i <= n; i++) edge_cnt[find(x[i])]++;     for (int i = 1; i <= x_n + y_n; i++) {       if (fa[i] != i) continue;       int fac = 1;       for (int j = 1; j <= node_cnt[i]; j++) fac = fac * 2 % MOD;       if (edge_cnt[i] < node_cnt[i]) fac--;       ans = (long long)ans * fac % MOD;     }     printf( %d n , ans);   }   int main() {     init();     solve();   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000001;   template <class T, class U>   ostream &operator<<(ostream &out, const pair<T, U> &p) {     return out << p.first <<     << p.second;   }   template <class T>   ostream &operator<<(ostream &out, const vector<T> &v) {     for (typeof((v).begin()) i = ((v).begin()); i != (v).end(); ++i) {       out << *i <<    ;     }     return out;   }   template <class T, class U>   istream &operator>>(istream &in, pair<T, U> &p) {     return in >> p.first >> p.second;   }   template <class T>   istream &operator>>(istream &in, vector<T> &v) {     for (typeof((v).begin()) i = ((v).begin()); i != (v).end(); ++i) {       in >> (*i);     }     return in;   }   template <class T>   ostream &operator,(ostream &out, const T &t) {     return out << t;   }   template <class T>   istream &operator,(istream &in, T &t) {     return in >> t;   }   int io_init() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout, fixed, setprecision(9);     return 1;   }   int _io_dummy = io_init();   template <class T, class U>   bool remin(T &a, const U &b) {     return b < a ? a = b, true : false;   }   template <class T, class U>   bool remax(T &a, const U &b) {     return b > a ? a = b, true : false;   }   const int N = 1000000;   int D[N];   void calcPrimes(int n = N) {     for (int i = 2; i * i < n; ++i) {       if (D[i]) {         continue;       }       for (int j = i * i; j < n; j += i) {         D[j] = i;       }     }   }   bool isPrime(int x) { return x > 1 && D[x] == 0; }   int rev(int x) {     ostringstream oss;     oss, x;     string s = oss.str();     reverse((s).begin(), (s).end());     istringstream iss(s);     iss, x;     return x;   }   int main() {     calcPrimes();     string s =          qd ucyhf yi q fhycu dkcruh mxeiu huluhiu yi q tyvvuhudj fhycu dkcruh.            oekh jqia yi je vydt jxu djx ucyhf. n ;     s +=  jxu ydfkj sediyiji ev q iydwbu ydjuwuh d (1 <= d <= 11184) - jxu             edu-rqiut ydtun ev jxu ucyhf je vydt n ;     s +=  ekjfkj q iydwbu dkcruh. ;     for (int i = 0; i < (10); ++i) {       for (typeof((s).begin()) c = ((s).begin()); c != (s).end(); ++c) {         if (!isalpha(*c)) continue;         if ((*c)++ ==  z ) *c =  a ;       }     }     cerr, s,   n ;     int x;     cin, x;     int n = 0, r;     for (int i = 13; i < N; i += 2) {       if (isPrime(i) && (r = rev(i)) != i && isPrime(r)) {         ++n;         if (n == x) {           cout, i,   n ;           break;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   const int MAXN = 1e6 + 10;   pair<int, pair<int, int> > A[MAXN];   int HX[MAXN], HY[MAXN];   int fa[MAXN];   int X[MAXN], Y[MAXN];   int ans[MAXN];   int Find(int x) { return fa[x] == x ? x : fa[x] = Find(fa[x]); }   void uni(int x, int y) {     int fx = Find(x), fy = Find(y);     if (fx != fy) {       fa[fx] = fy;     }   }   int main() {     while (scanf( %d%d , &n, &m) != EOF) {       for (int i = 0; i < n * m; i++) {         fa[i] = i;       }       for (int i = 0; i < n * m; i++) {         scanf( %d , &A[i].first);         A[i].second.first = i / m;         A[i].second.second = i % m;       }       sort(A, A + n * m);       memset(ans, 0, sizeof(ans));       int j = -1;       for (int i = j + 1; i < n * m; i++) {         if (i + 1 < n * m && A[i].first == A[i + 1].first) continue;         for (int k = j + 1; k <= i; k++) {           int p = A[k].second.first * m + A[k].second.second;           int x = A[k].second.first, y = A[k].second.second;           HX[x] = p;           HY[y] = p;         }         for (int k = j + 1; k <= i; k++) {           int p = A[k].second.first * m + A[k].second.second;           int x = A[k].second.first, y = A[k].second.second;           uni(HX[x], p);           uni(HY[y], p);         }         for (int k = j + 1; k <= i; k++) {           int p = A[k].second.first * m + A[k].second.second;           int x = A[k].second.first, y = A[k].second.second;           int fp = Find(p);           ans[fp] = max(ans[fp], max(X[x], Y[y]) + 1);         }         for (int k = j + 1; k <= i; k++) {           int p = A[k].second.first * m + A[k].second.second;           int x = A[k].second.first, y = A[k].second.second;           int fp = Find(p);           X[x] = max(X[x], ans[fp]);           Y[y] = max(Y[y], ans[fp]);         }         j = i;       }       for (int i = 0; i < n * m; i++) {         printf( %d  , ans[Find(i)]);         if (i % m == m - 1) puts(  );       }     }   }
#include <bits/stdc++.h>   using namespace std;   int p2[203];   int p5[203];   int dpcur[203][5003][2];   int dpnxt[203][5003][2];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       long long int x;       cin >> x;       while (x % 2 == 0) {         x /= 2;         p2[i]++;       }       while (x % 5 == 0) {         x /= 5;         p5[i]++;       }     }     memset(dpcur, -1, sizeof(dpcur));     memset(dpnxt, -1, sizeof(dpnxt));     dpcur[k][0][0] = 0;     if (p2[1] >= p5[1]) {       dpcur[k - 1][p2[1] - p5[1]][0] = p5[1];     } else {       dpcur[k - 1][p5[1] - p2[1]][1] = p2[1];     }     for (int i = 2; i <= n; i++) {       for (int K = k; K >= max(0, k - (i - 1)); K--) {         for (int excess_cnt = 0; excess_cnt <= min(5000, 60 * (i - 1));              excess_cnt++) {           if (dpcur[K][excess_cnt][0] != -1) {             dpnxt[K][excess_cnt][0] =                 max(dpnxt[K][excess_cnt][0], dpcur[K][excess_cnt][0]);             int cnt2 = p2[i] + excess_cnt;             int cnt5 = p5[i];             if (cnt2 >= cnt5 && K - 1 >= 0) {               dpnxt[K - 1][min(cnt2 - cnt5, 5000)][0] =                   max(dpnxt[K - 1][min(cnt2 - cnt5, 5000)][0],                       dpcur[K][excess_cnt][0] + cnt5);             } else if (cnt5 > cnt2 && K - 1 >= 0) {               dpnxt[K - 1][min(cnt5 - cnt2, 5000)][1] =                   max(dpnxt[K - 1][min(cnt5 - cnt2, 5000)][1],                       dpcur[K][excess_cnt][0] + cnt2);             }           }           if (dpcur[K][excess_cnt][1] != -1) {             dpnxt[K][excess_cnt][1] =                 max(dpnxt[K][excess_cnt][1], dpcur[K][excess_cnt][1]);             int cnt2 = p2[i];             int cnt5 = p5[i] + excess_cnt;             if (cnt2 >= cnt5 && K - 1 >= 0) {               dpnxt[K - 1][min(cnt2 - cnt5, 5000)][0] =                   max(dpnxt[K - 1][min(cnt2 - cnt5, 5000)][0],                       dpcur[K][excess_cnt][1] + cnt5);             } else if (cnt5 > cnt2 && K - 1 >= 0) {               dpnxt[K - 1][min(cnt5 - cnt2, 5000)][1] =                   max(dpnxt[K - 1][min(cnt5 - cnt2, 5000)][1],                       dpcur[K][excess_cnt][1] + cnt2);             }           }         }       }       for (int K = k; K >= max(0, k - i); K--) {         for (int excess_cnt = 0; excess_cnt <= min(5000, 60 * i); excess_cnt++) {           for (int excess = 0; excess <= 1; excess++) {             dpcur[K][excess_cnt][excess] = dpnxt[K][excess_cnt][excess];           }         }       }       memset(dpnxt, -1, sizeof(dpnxt));     }     int ans = 0;     for (int excess_cnt = 0; excess_cnt <= 5000; excess_cnt++) {       for (int excess = 0; excess <= 1; excess++) {         ans = max(ans, dpcur[0][excess_cnt][excess]);       }     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx )   using namespace std;   const long long mod = 998244353;   long long binpow(long long a, long long n) {     if (n == 0) return 1;     if (n % 2 == 1) {       return (binpow(a, n - 1) * a) % mod;       ;     } else {       long long b = binpow(a, n / 2);       return (b * b) % mod;     }   }   long long f[500];   long long f_obr[500];   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     f[0] = 1;     f_obr[0] = 1;     for (long long i = 1; i < 500; ++i) {       f[i] = f[i - 1] * i;       f[i] %= mod;       f_obr[i] = binpow(f[i], mod - 2);     }     long long d;     cin >> d;     vector<long long> pr;     pr.reserve(1e7 + 5);     for (long long i = 2; i * i <= d; ++i) {       if (d % i == 0) {         pr.push_back(i);         while (d % i == 0) d /= i;       }     }     if (d > 1) pr.push_back(d);     int q;     cin >> q;     for (int i = 0; i < q; ++i) {       long long v[2];       cin >> v[0] >> v[1];       vector<long long> vc[2];       vector<int> cnt[2];       for (int j = 0; j < 2; ++j)         for (int k = 0; k < int(pr.size()); ++k)           if (v[j] % pr[k] == 0) {             vc[j].push_back(pr[k]);             cnt[j].push_back(0);             while (v[j] % pr[k] == 0) {               cnt[j].back()++;               v[j] /= pr[k];             }           }       int uk = 0;       vector<int> res[2];       for (int j = 0; j < int(cnt[0].size()); ++j) {         while (uk < int(cnt[1].size()) && vc[1][uk] <= vc[0][j]) {           if (vc[1][uk] == vc[0][j]) {             if (cnt[0][j] > cnt[1][uk])               res[0].push_back(cnt[0][j] - cnt[1][uk]);             else               res[1].push_back(cnt[1][uk] - cnt[0][j]);           } else             res[1].push_back(cnt[1][uk]);           ++uk;         }         if (!(uk > 0 && vc[1][uk - 1] == vc[0][j])) res[0].push_back(cnt[0][j]);       }       while (uk < int(cnt[1].size())) {         res[1].push_back(cnt[1][uk]);         ++uk;       }       int sum[2];       sum[0] = 0;       sum[1] = 0;       long long ans = 1;       for (int j = 0; j < 2; ++j)         for (int k = 0; k < int(res[j].size()); ++k) {           sum[j] += res[j][k];           ans *= f_obr[res[j][k]];           ans %= mod;         }       ans *= f[sum[0]];       ans %= mod;       ans *= f[sum[1]];       ans %= mod;       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, a[1000001], mx[1000001], cnt, maxi, ans;   int main() {     cin >> n;     for (long long i = 1; i <= n; ++i) {       cin >> a[i];       mx[i] = -1;       for (long long j = 1; j <= a[i]; ++j) {         long long k;         cin >> k;         mx[i] = max(mx[i], k);       }     }     for (long long i = 1; i <= n; ++i) {       maxi = max(maxi, mx[i]);     }     for (long long i = 1; i <= n; ++i) {       cnt += (maxi - mx[i]) * a[i];     }     cout << cnt;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long int n, i, x;     cin >> n;     long long int a[2 * n];     for (i = 0; i < 2 * n; i++) {       cin >> a[i];     }     sort(a, a + 2 * n);     x = (a[n - 1] - a[0]) * (a[2 * n - 1] - a[n]);     for (i = 0; i < n; i++) {       x = min(x, (a[i + n - 1] - a[i]) * (a[2 * n - 1] - a[0]));     }     cout << x;   }
#include <bits/stdc++.h>   using namespace std;   char a[300099];   char ans[300099];   int c[200000];   int b;   int main() {     while (~scanf( %s , a)) {       memset(c, 0, sizeof(c));       scanf( %d , &b);       int len = strlen(a);       for (int i = 0; i < b; i++) {         int pt;         scanf( %d , &pt);         pt--;         c[pt]++;       }       for (int i = 0; i < len / 2; i++) {         if (i == 0) {           if (c[i] % 2)             ans[i] = a[len - 1 - i], ans[len - 1 - i] = a[i];           else             ans[i] = a[i], ans[len - 1 - i] = a[len - 1 - i];         } else {           c[i] += c[i - 1];           if (c[i] % 2)             ans[i] = a[len - 1 - i], ans[len - 1 - i] = a[i];           else             ans[i] = a[i], ans[len - 1 - i] = a[len - 1 - i];         }       }       if (len % 2) ans[len / 2] = a[len / 2];       ans[len] =   0 ;       printf( %s n , ans);     }     return 0;   }
#include <bits/stdc++.h>   long long int a, b;   int main() {     scanf( %lld %lld , &a, &b);     if (a % 2 == 0) {       if (2 * b - 1 < a) {         printf( %lld , 2 * b - 1);       } else {         printf( %lld , (b - a / 2) * 2);       }     } else {       if (2 * b - 1 <= a) {         printf( %lld , 2 * b - 1);       } else {         printf( %lld , ((b - a / 2) - 1) * 2);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 300100;   int n, m, a[maxn], ans = -1;   int f[maxn][30], du[maxn], Time;   char s[maxn];   int dfn[maxn], low[maxn];   vector<int> g[maxn];   vector<int>::iterator it;   bool loop = 0, in[maxn];   stack<int> q;   void dfs(int x) {     dfn[x] = low[x] = ++Time;     in[x] = 1;     q.push(x);     for (int i = 0; i < g[x].size(); ++i) {       int k = g[x][i];       if (!dfn[k]) {         dfs(k);         low[x] = min(low[x], low[k]);       } else if (in[k] && dfn[k] < low[x]) {         low[x] = min(low[x], dfn[k]);       }       for (int j = 0; j < 26; ++j) {         f[x][j] = max(f[x][j], f[k][j]);       }     }     if (dfn[x] == low[x]) {       int cnt = 0;       while (1) {         int tem = q.top();         q.pop();         cnt++;         in[tem] = 0;         if (tem == x) break;       }       if (cnt > 1) loop = 1;     }     ++f[x][a[x]];   }   int main() {     scanf( %d%d , &n, &m);     scanf( %s , s + 1);     for (int i = 1; i <= n; ++i) {       a[i] = s[i] -  a ;     }     for (int i = 1, x, y; i <= m; ++i) {       scanf( %d%d , &x, &y);       if (x == y) loop = 1;       g[x].push_back(y), du[y]++;     }     if (loop) {       printf( -1 n );       return 0;     }     for (int i = 1; i <= n; ++i) {       if (!du[i]) {         dfs(i);         if (loop == 1) {           printf( -1 n );           return 0;         }         for (int j = 0; j < 26; ++j) {           ans = max(f[i][j], ans);         }       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, cnt, ans[200009], sum[200009], dp[200009][26], s1[200009], s2[200009],       f[200009];   char a[200009], b[200009];   void solve(int u, int v) {     int i;     for (i = 1; i <= n; i++) s1[i] = (a[i] ==  a  + u);     for (i = 1; i <= m; i++) {       s2[i] = (b[i] ==  a  + v);       if (i > 1) {         f[i] = f[i - 1];         for (; f[i] && s2[f[i] + 1] != s2[i]; f[i] = f[f[i]])           ;         f[i] += (s2[f[i] + 1] == s2[i]);       }     }     int k = 1;     for (i = 1; i <= n; i++) {       for (; k && s2[k + 1] != s1[i]; k = f[k])         ;       k += (s2[k + 1] == s1[i]);       if (k == m) {         dp[i - m + 1][u] = v;         k = f[k];       }     }   }   int main() {     scanf( %d%d%s%s , &n, &m, a + 1, b + 1);     int i, j;     memset(dp, -1, sizeof(dp));     for (i = 0; i < 26; i++) {       for (j = 0; j < 26; j++) solve(i, j);       for (j = 1; j <= n; j++) {         sum[j] = sum[j - 1] + (a[j] ==  a  + i);         if (j >= m && sum[j] == sum[j - m]) dp[j - m + 1][i] = -2;       }     }     for (i = 1; i <= n - m + 1; i++) {       for (j = 0; j < 26; j++) {         if (dp[i][j] == -1) break;         if (dp[i][j] == -2) continue;         if (dp[i][dp[i][j]] == -2) dp[i][dp[i][j]] = j;         if (dp[i][dp[i][j]] != j) break;       }       if (j == 26) ans[++cnt] = i;     }     printf( %d n , cnt);     for (i = 1; i <= cnt; i++) printf( %d%c , ans[i], i < cnt ?     :   n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int P;   long long int a[501];   long long int dp[501][501];   void solve() {     long long int n, m, b, P, i, j, k;     cin >> n >> m >> b >> P;     for (i = 1; i <= n; i++) {       cin >> a[i];     }     memset(dp, 0, sizeof(dp));     long long int ans = 0;     dp[0][0] = 1;     for (i = 1; i <= n; i++) {       for (j = 0; j < m; j++) {         for (k = 0; k + a[i] <= b; k++) {           dp[j + 1][k + a[i]] = (dp[j + 1][k + a[i]] + dp[j][k]) % P;         }       }     }     for (i = 0; i <= b; i++) {       ans += dp[m][i];       ans %= P;     }     cout << ans % P;   }   int main() {     long long int t = 1;     while (t--) {       solve();     }     return 0;   }