malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   map<int, int> vis;   string s[1000009];   int n, m, i;   bool dfs(int x, int y) {     if (x == n - 1 && y == m - 1) return true;     if (x < 0 || y < 0 || x >= n || y >= m || vis[y + x * m] == 1 ||         s[x][y] ==  # )       return false;     if (x || y) {       vis[y + x * m] = 1;     }     return dfs(x + 1, y) || dfs(x, y + 1);   }   int main() {     cin >> n >> m;     for (i = 0; i < n; i++) cin >> s[i];     if (dfs(0, 0) == false) {       cout <<  0 ;       return 0;     }     if (dfs(0, 0) == false) {       cout <<  1 ;       return 0;     }     cout <<  2 ;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int init[110];   string lst[110];   vector<int> fin;   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     for (int i = (int)0; i < (int)n; ++i) cin >> lst[i];     for (int i = (int)0; i < (int)n; ++i) cin >> init[i];     bool flag = 1;     while (flag) {       flag = 0;       for (int i = (int)0; i < (int)n; ++i)         if (init[i] == 0) {           flag = 1;           fin.push_back(i + 1);           for (int j = (int)0; j < (int)n; ++j) init[j] -= lst[i][j] -  0 ;         }     }     cout << fin.size() << endl;     for (int ele : fin) cout << ele <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int mm[110][110];   int tmp[110][110];   void draw(int a, int b, int v) {     for (int lx = 0; lx < a; lx++)       for (int ly = 0; ly < b; ly++) tmp[lx][ly] += v;     return;   }   void prt(int a, int b) {     for (int lx = 0; lx < a; lx++) {       for (int ly = 0; ly < b; ly++) printf( %c , tmp[lx][ly] ?  W  :  B );       puts(  );     }     return;   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int lx = 0; lx < n; lx++) {       char buf[200];       scanf( %s , buf);       for (int ly = 0; ly < m; ly++) mm[lx][ly] = (buf[ly] ==  W );     }     int cnt = 1;     for (int lx = 0; lx < n; lx++)       for (int ly = 0; ly < m; ly++) tmp[lx][ly] = mm[n - 1][m - 1];     for (int cc = n + m - 3; cc >= 0; cc--) {       for (int x = 0; x <= cc; x++) {         int y = cc - x;         if (x >= n or y >= m) continue;         if (tmp[x][y] != mm[x][y]) {           draw(x + 1, y + 1, mm[x][y] - tmp[x][y]), cnt++;         }       }     }     printf( %d n , cnt);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int gcd(long long int a, long long int b) {     return (!b) ? a : gcd(b, a % b);   }   int n, k;   void solve() {     cin >> n >> k;     string s;     cin >> s;     vector<vector<int>> mvs;     int mxs = 0;     int cnt = 0;     while (cnt <= n) {       vector<int> cr;       for (int i = 0; i <= (int)s.size() - 2; i++) {         if (s[i] ==  R  && s[i + 1] ==  L ) {           cr.push_back(i);           s[i] =  L ;           s[i + 1] =  R ;           i += 1;         }       }       if ((int)cr.size() == 0) break;       mvs.push_back(cr);       mxs += (int)cr.size();       cnt += 1;     }     if (k >= (int)mvs.size() && k <= mxs) {       int rem = (int)mvs.size();       for (auto fv : mvs) {         vector<int> cv = fv;         int i = 0;         while (i < (int)cv.size()) {           int ch = 1;           if (rem == k) ch = (int)cv.size() - i;           cout << ch <<    ;           for (int j = 0; j < ch; j++) {             cout << cv[i] + 1 <<    ;             i += 1;           }           cout <<   n ;           k -= 1;         }         rem -= 1;       }     } else {       cout << -1;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solve();   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (a == 0) return b;     return gcd(b % a, a);   }   vector<string> results(100001);   vector<pair<int, string> > wishes;   vector<pair<int, string> > S_M, M_L, L_XL, XL_XXL, XXL_XXXL;   bool compare(pair<int, string> a, pair<int, string> b) {     if (a.second ==  S,M ) return false;     if (a.second ==  M,L ) return b.second ==  S,M ;     if (a.second ==  L,XL ) return b.second ==  S,M  || b.second ==  M,L ;     if (a.second ==  XL,XXL ) return b.second !=  XXL,XXXL ;     return true;   }   int main() {     int S = 0, M = 0, L = 0, XL = 0, XXL = 0, XXXL = 0;     cin >> S >> M >> L >> XL >> XXL >> XXXL;     map<string, int> sizes;     sizes[ S ] = S;     sizes[ M ] = M;     sizes[ L ] = L;     sizes[ XL ] = XL;     sizes[ XXL ] = XXL;     sizes[ XXXL ] = XXXL;     int n;     string s;     cin >> n;     unsigned long long xx = 0;     for (int i = 0; i < n; i++) {       cin >> s;       int pos = s.find( , );       if (pos == string::npos) {         results[i] = s;         if (sizes[s] > 0)           sizes[s]--;         else {           cout <<  NO ;           return 0;         }       } else {         if (s ==  S,M ) S_M.push_back(make_pair(i, s));         if (s ==  M,L ) M_L.push_back(make_pair(i, s));         if (s ==  L,XL ) L_XL.push_back(make_pair(i, s));         if (s ==  XL,XXL ) XL_XXL.push_back(make_pair(i, s));         if (s ==  XXL,XXXL ) {           XXL_XXXL.push_back(make_pair(i, s));           xx++;         }       }     }     wishes.insert(wishes.end(), S_M.begin(), S_M.end());     wishes.insert(wishes.end(), M_L.begin(), M_L.end());     wishes.insert(wishes.end(), L_XL.begin(), L_XL.end());     wishes.insert(wishes.end(), XL_XXL.begin(), XL_XXL.end());     wishes.insert(wishes.end(), XXL_XXXL.begin(), XXL_XXXL.end());     for (int i = 0; i < wishes.size(); i++) {       pair<int, string> wish = wishes[i];       string sz = wish.second;       int ind = wish.first;       int pos = sz.find( , );       string first = sz.substr(0, pos);       string second = sz.substr(pos + 1);       if (sizes[first] == 0 && sizes[second] == 0) {         cout <<  NO ;         return 0;       }       if (sizes[first] != 0) {         results[ind] = first;         sizes[first]--;       } else {         results[ind] = second;         sizes[second]--;       }     }     cout <<  YES  << endl;     for (int i = 0; i < n; i++) cout << results[i] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s1[1000], s2[1000], v[1000], s[1000];   int d[200][200][200];   int p[200][200][200][3];   int pp[1000];   int main() {     int i, j, k, l1, l2, l, tmp, ans, bk, ti, tj, tk, m;     scanf( %s%s%s , s1, s2, v);     l1 = strlen(s1);     l2 = strlen(s2);     l = strlen(v);     pp[0] = 0;     pp[1] = 0;     i = 0;     j = 1;     while (1) {       if (j == l) break;       pp[j] = i;       while ((i > 0) && (v[i] != v[j])) i = pp[i];       if (v[i] == v[j]) {         i++;         j++;       } else         j++;     }     memset(d, -1, sizeof(d));     d[0][0][0] = 0;     for (i = 0; i <= l1; i++)       for (j = 0; j <= l2; j++)         for (k = 0; k < l; k++)           if (d[i][j][k] != -1) {             if (i < l1)               if (d[i][j][k] > d[i + 1][j][k]) {                 d[i + 1][j][k] = d[i][j][k];                 p[i + 1][j][k][0] = i;                 p[i + 1][j][k][1] = j;                 p[i + 1][j][k][2] = k;               }             if (j < l2)               if (d[i][j][k] > d[i][j + 1][k]) {                 d[i][j + 1][k] = d[i][j][k];                 p[i][j + 1][k][0] = i;                 p[i][j + 1][k][1] = j;                 p[i][j + 1][k][2] = k;               }             if ((i < l1) && (j < l2) && (s1[i] == s2[j])) {               tmp = k;               while ((tmp > 0) && (v[tmp] != s1[i])) tmp = pp[tmp];               if (v[tmp] == s1[i]) tmp++;               if (tmp < l) {                 if (d[i][j][k] + 1 > d[i + 1][j + 1][tmp]) {                   d[i + 1][j + 1][tmp] = d[i][j][k] + 1;                   p[i + 1][j + 1][tmp][0] = i;                   p[i + 1][j + 1][tmp][1] = j;                   p[i + 1][j + 1][tmp][2] = k;                 }               }             }           }     ans = -1;     for (k = 0; k < l; k++)       if (d[l1][l2][k] > ans) {         ans = d[l1][l2][k];         bk = k;       }     if (ans == 0)       printf( 0 n );     else {       m = 0;       ti = l1;       tj = l2;       tk = bk;       while ((ti != 0) || (tj != 0)) {         i = p[ti][tj][tk][0];         j = p[ti][tj][tk][1];         k = p[ti][tj][tk][2];         if ((i < ti) && (j < tj)) {           s[m] = s1[i];           m++;         }         ti = i;         tj = j;         tk = k;       }       s[m] =   0 ;       reverse(s, s + m);       printf( %s n , s);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int mex = 1e9;     for (int i = 0; i < m; i++) {       int l, r;       cin >> l >> r;       mex = min(mex, r - l + 1);     }     cout << mex <<   n ;     for (int i = 0; i < n; i++) {       cout << i % mex <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int maxn = 1e4 + 5;   class Matrix {    public:     long long a[3][3];     int n;     void Init(int key) {       memset(a, 0, sizeof a);       if (key)         for (int i = 0; i < n; i++) a[i][i] = 1;     }     Matrix operator*(const Matrix& b) {       Matrix c;       c.n = n;       c.Init(0);       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++)           for (int k = 0; k < n; k++)             c.a[i][j] = (c.a[i][j] + a[i][k] * b.a[k][j] % mod) % mod;       return c;     }     Matrix Power(long long t) {       Matrix ans, p = *this;       ans.n = p.n;       ans.Init(1);       while (t) {         if (t & 1) ans = ans * p;         p = p * p;         t >>= 1;       }       return ans;     }     void Print() {       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) {           if (j == 0)             printf( %lld , a[i][j]);           else             printf(  %lld , a[i][j]);         }         puts(  );       }     }   };   struct node {     int x, tag;     long long y;     friend bool operator<(const node& a, const node& b) { return a.y < b.y; }   } a[maxn * 2];   long long sum[3], b[3];   void calc(long long n) {     Matrix f, A;     f.Init(0);     A.Init(0);     f.n = A.n = 3;     for (int i = 0; i < 3; i++) {       for (int j = 0; j < 3; j++) {         if (sum[j] == 0)           f.a[i][j] = 1;         else           f.a[i][j] = 0;       }     }     f.a[0][2] = f.a[2][0] = 0;     A.a[0][0] = b[0], A.a[0][1] = b[1], A.a[0][2] = b[2];     A = A * f.Power(n);     b[0] = A.a[0][0], b[1] = A.a[0][1], b[2] = A.a[0][2];   }   int main() {     int n;     long long m;     scanf( %d%lld , &n, &m);     int cnt = 0;     for (int i = 1; i <= n; i++) {       int x;       long long l, r;       scanf( %d%lld%lld , &x, &l, &r);       a[++cnt].x = x - 1, a[cnt].y = l - 1, a[cnt].tag = 1;       a[++cnt].x = x - 1, a[cnt].y = r, a[cnt].tag = -1;     }     sort(a + 1, a + cnt + 1);     b[0] = b[2] = 0, b[1] = 1;     long long cur = 1;     for (int i = 1; i <= cnt; i++) {       calc(a[i].y - cur);       cur = a[i].y;       sum[a[i].x] += a[i].tag;     }     calc(m - cur);     printf( %lld n , b[1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool smin(T &a, const T &b) {     return b < a ? a = b, 1 : 0;   }   template <typename T>   inline bool smax(T &a, const T &b) {     return a < b ? a = b, 1 : 0;   }   const long long N = 1e5 + 10, mod = (long long)1e9 + 7;   long long n, k, ps[N], f[N], inv[N], pw10[N];   string s;   long long pw(long long x, long long y) {     x %= mod;     long long ret = 1;     for (; y; y >>= 1, (x *= x) %= mod)       if (y & 1) (ret *= x) %= mod;     return ret;   }   long long C(long long n, long long r) {     if (r > n || r < 0 || n < 0) return 0;     return ((f[n] * inv[r] % mod) * inv[n - r] % mod) % mod;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> k >> s;     ps[0] = s[0] -  0 ;     for (long long i = 1; i < n; ++i) (ps[i] = ps[i - 1] + (s[i] -  0 )) %= mod;     f[0] = inv[0] = 1;     for (long long i = 1; i < N; ++i) {       (f[i] = f[i - 1] * i) %= mod;       inv[i] = pw(f[i], mod - 2);     }     pw10[0] = 1;     for (long long i = 1; i < N; ++i) (pw10[i] = pw10[i - 1] * 10) %= mod;     long long res = 0;     for (long long sz = 0; sz <= n - 2; ++sz) {       long long add =           pw10[sz] * C(n - sz - 2, k - 1) % mod * ps[n - sz - 2] % mod;       (res += add) %= mod;     }     for (long long i = 0; i < n; ++i) {       long long add = (s[i] -  0 ) * pw10[n - i - 1] % mod * C(i, k);       (res += add) %= mod;     }     cout << res <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   const int inf = 0x3f3f3f3f;   const double eps = 1e-8;   map<int, int> ma;   int n, x, num;   int getId(int x) {     if (ma.count(x) == 0) {       ma[x] = num++;     }     return ma[x];   }   int cnt[maxn];   vector<int> v;   int main() {     while (~scanf( %d , &n)) {       memset(cnt, 0, sizeof(cnt));       num = 1;       ma.clear();       v.clear();       for (int i = 1; i <= n; i++) {         scanf( %d , &x);         cnt[getId(x)]++;         x = getId(x);       }       for (int i = 0; i <= n + 1; i++) {         if (cnt[i] != 0) v.push_back(cnt[i]);       }       sort(v.begin(), v.end());       int now = 0, ans = 0;       int len = v.size();       for (int i = 1; i <= v[len - 1]; i++) {         int sum = 0;         now = 0;         for (int j = i;;) {           int pos = lower_bound(v.begin() + now, v.end(), j) - v.begin();           if (pos == len) break;           now = pos + 1;           sum += j;           j = j * 2;         }         ans = max(ans, sum);       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC target(         sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( fast-math )   using namespace std;   mt19937 rnd(time(0) + 228 +  k  +  e  +  k  +  e  +  r  +  o  +  f  +  e  +                y );   vector<int> genvec(int sz, int minelem, int maxelem) {     ++maxelem;     vector<int> ans(sz);     for (int i = 0; i < sz; ++i) {       ans[i] = minelem + rnd() % (maxelem - minelem);     }     return ans;   }   const long double EPS = 1e-14;   bool checkprime(int x) {     for (int i = 2; i * i <= x; ++i)       if (x % i == 0) return 0;     return 1;   }   const long double PI = acos(-1);   const int MOD7 = 1000000007;   const int MOD9 = 1000000009;   const long long INF = 2e18;   int mod = MOD7;   const int inf = 1e9;   signed main() {     ios_base::sync_with_stdio(0);     cout.tie(0);     cin.tie(0);     srand(time(NULL));     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> p(2 * n);       for (long long i = 0; i < p.size(); ++i) cin >> p[i];       ;       int mx = 0;       vector<int> luls;       int cnt = 0;       for (int i : p) {         if (i > mx) {           mx = i;           if (cnt) luls.push_back(cnt);           cnt = 1;         } else {           ++cnt;         }       }       luls.push_back(cnt);       vector<bool> dp(n + 1);       dp[0] = 1;       int ps = 0;       for (int i : luls) {         ps += i;         for (int sum = n; sum >= 0; --sum) {           if (!dp[sum]) continue;           if (ps - sum - i > n) continue;           if (sum + i <= n) {             dp[sum + i] = 1;           }         }       }       cout << (dp[n] ?  YES  :  NO ) << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   ifstream fin( input.txt );   ofstream fout( output.txt );   bool isPrime(int x) {     if (x <= 4 || x % 2 == 0 || x % 3 == 0) return x == 2 || x == 3;     for (int i = 5; i * i <= x; i += 6)       if (x % i == 0 || x % (i + 2) == 0) return 0;     return 1;   }   inline void boostIO() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int main() {     boostIO();     int n, s;     cin >> n >> s;     int prev = 0;     int h = 0;     int m = 0;     for (int i = 0; i < (n); ++i) {       cin >> h >> m;       m += h * 60;       if (i == 0 && m - prev >= s + 1) {         cout << 0 <<     << 0 << endl;         return 0;       }       if (m - prev >= s * 2 + 2) {         cout << (prev + s + 1) / 60 <<     << (prev + s + 1) % 60 << endl;         return 0;       }       prev = m;     }     cout << (prev + s + 1) / 60 <<     << (prev + s + 1) % 60;     return 0;   }
#include <bits/stdc++.h>   inline int read() {     int data = 0, w = 1;     char ch = getchar();     while (ch !=  -  && (ch <  0  || ch >  9 )) ch = getchar();     if (ch ==  - ) w = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) data = data * 10 + (ch ^ 48), ch = getchar();     return data * w;   }   const int N(1e5 + 10), M(105), Mod(998244353);   int n, K, L, f[N][M], s[N], len[N][M], a[N];   int main() {     n = read(), K = read(), L = read();     for (int i = 1; i <= n; i++) a[i] = read();     for (int i = 1; i <= n; i++)       for (int j = 1; j <= K; j++)         if (a[i] == -1 || a[i] == j) len[i][j] = len[i - 1][j] + 1;     s[0] = 1;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= K; j++)         if (a[i] == -1 || a[i] == j) {           f[i][j] = s[i - 1];           if (i >= L && len[i][j] >= L)             f[i][j] = (f[i][j] - s[i - L] + Mod) % Mod,             f[i][j] = (f[i][j] + f[i - L][j]) % Mod;           s[i] = (s[i] + f[i][j]) % Mod;         }     printf( %d n , s[n]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5006;   const int mod = 1000000009;   double x[maxn], y[maxn], z[maxn];   double d[maxn][maxn];   int n;   double dis(double x1, double y1, double z1, double x2, double y2, double z2) {     double dx = x1 - x2;     double dy = y1 - y2;     double dz = z1 - z2;     return sqrt(dx * dx + dy * dy + dz * dz);   }   double getans() {     double ret = 100000000000.0;     for (int i = 1; i < n; ++i)       for (int j = i + 1; j < n; ++j) {         double dd = d[i][j] + d[0][i] + d[0][j];         ret = min(ret, dd);       }     return ret;   }   void init() {     for (int i = 0; i < n; ++i)       for (int j = 0; j < n; ++j)         d[i][j] = dis(x[i], y[i], z[i], x[j], y[j], z[j]);   }   int main() {     while (~scanf( %d , &n)) {       for (int i = 0; i < n; ++i) {         scanf( %lf%lf%lf , x + i, y + i, z + i);       }       init();       double ans = getans();       ans /= 2;       printf( %.9lf n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s;   int main() {     long long k, d, t;     scanf( %lld %lld %lld , &k, &d, &t);     if (k % d == 0) {       printf( %.10lf n , (double)t);       return 0;     }     t *= 2;     long long period = (k / d + 1) * d;     long long periodPoints = 2 * k + period - k;     long long nPeriods = t / periodPoints;     long long timeSpent = nPeriods * periodPoints;     long long rest = t - timeSpent;     if (rest == 0) {       printf( %.10lf n , (double)nPeriods * period);       return 0;     }     if (2 * k >= rest) {       printf( %.10lf n , (double)nPeriods * period + rest / 2.0);       return 0;     }     printf( %.10lf n , (double)nPeriods * period + rest - k);   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void gn(T &first) {     char c, sg = 0;     while (c = getchar(), (c >  9  || c <  0 ) && c !=  - )       ;     for ((c ==  -  ? sg = 1, c = getchar() : 0), first = 0; c >=  0  && c <=  9 ;          c = getchar())       first = (first << 1) + (first << 3) + c -  0 ;     if (sg) first = -first;   }   template <class T1, class T2>   inline void gn(T1 &x1, T2 &x2) {     gn(x1), gn(x2);   }   char S1[1000100], S2[1000100];   char B[1000100 * 3];   int fail[1000100 * 3];   void build_fail_function(char B[], int len) {     int j = fail[0] = -1;     for (int i = 1; i < len; i++) {       while (j != -1 and B[j + 1] != B[i]) j = fail[j];       if (B[j + 1] == B[i]) j++;       fail[i] = j;     }   }   int main() {     int n;     gn(n);     n--;     scanf( %s %s , S1, S2);     for (int i = 0; i < n; i++) {       if (S1[i] ==  N )         S1[i] =  S ;       else if (S1[i] ==  S )         S1[i] =  N ;       else if (S1[i] ==  W )         S1[i] =  E ;       else         S1[i] =  W ;     }     int nn = 0;     for (int i = 0; i < n; i++) B[nn++] = S1[n - i - 1];     B[nn++] =  * ;     for (int i = 0; i < n; i++) B[nn++] = S2[i];     build_fail_function(B, nn);     if (fail[nn - 1] == -1) return puts( YES );     puts( NO );   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2500 + 5;   int cnt = 0;   int rec[MAXN], mp[MAXN][MAXN], dp[MAXN][MAXN];   bool prime[MAXN];   void init(int n) {     memset(prime, true, sizeof(prime));     prime[0] = prime[1] = false;     for (int i = 2; i <= n; i++) {       if (prime[i]) rec[cnt++] = i;       for (int j = 0; j < cnt && rec[j] <= n / i; j++) {         prime[i * rec[j]] = false;         if (i % rec[j] == 0) break;       }     }   }   int main() {     init(600);     int n, m;     scanf( %d%d , &n, &m);     memset(mp, 0, sizeof(mp));     memset(dp, 0, sizeof(dp));     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         scanf( %1d , &mp[i][j]);         dp[i][j] = dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1] + mp[i][j];       }     int ans = dp[n][m], up = max(n, m);     for (int i = 0; rec[i] < up && i < cnt; i++) {       int tmp = 0;       for (int j = 0; j < n + rec[i]; j += rec[i])         for (int k = 0; k < m + rec[i]; k += rec[i]) {           int sum = dp[min(n, j + rec[i])][min(m, k + rec[i])] -                     dp[min(n, j)][min(m, k + rec[i])] -                     dp[min(n, j + rec[i])][min(m, k)] + dp[min(n, j)][min(m, k)];           tmp += min(rec[i] * rec[i] - sum, sum);         }       ans = min(ans, tmp);     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> prefix_function(string t, string s, int k) {     int m = (int)s.size();     s = t +  ?  + s;     int n = (int)s.length();     vector<int> pi(n);     for (int i = 1; i < n; ++i) {       int j = pi[i - 1];       while (j > 0 && s[i] != s[j]) j = pi[j - 1];       if (s[i] == s[j]) ++j;       pi[i] = j;     }     if (k >= (int)t.size()) {       for (int i = t.size() + 1, ii = 1; i < n; i++, ii++) {         if (pi[i] == t.size()) {           if (m - ii >= k) {             cout <<  Yes  << endl;             int x = ii - k + 1, y = ii + 1;             if (x <= 0) y += 1 - x, x += 1 - x;             cout << x <<     << y << endl;             exit(0);           }           int jj = ii - (int)t.size();           if (jj >= k) {             cout <<  Yes  << endl;             int x = jj - k + 1, y = jj + 1;             if (y > m - k + 1) x += m - k + 1 - y, y += m - k + 1 - y;             cout << x <<     << y << endl;             exit(0);           }         }       }     }     vector<int> occ(t.size() + 1, -1);     for (int i = t.size() + k; i < n; i++) {       int j = pi[i];       int idx = i - t.size() - 1;       while (occ[j] == -1) {         occ[j] = idx;         if (j == 0) break;         j = pi[j - 1];       }     }     return occ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, m, k;     cin >> n >> m >> k;     string s, t;     cin >> s >> t;     vector<int> L = prefix_function(t, s, k);     reverse(t.begin(), t.end());     reverse(s.begin(), s.end());     vector<int> R = prefix_function(t, s, k);     for (int i = 0; i < R.size(); i++) {       if (R[i] == -1) continue;       R[i] = n - 1 - R[i];     }     for (int l = 0; l <= m; l++) {       int r = m - l;       if (L[l] == -1 or R[r] == -1 or l > k or r > k) continue;       if (L[l] < R[r]) {         cout <<  Yes  << endl;         cout << L[l] - k + 1 + 1 <<     << R[r] + 1 << endl;         exit(0);       }     }     cout <<  No  << endl;     return 0;   }