malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 500055;   int n, m, r, k;   set<pair<int, int> > rec;   const int dir[2][4] = {{0, 0, 1, -1}, {1, -1, 0, 0}};   struct node {     int x, y, val;     node() {}     node(int _x, int _y, int _val) : x(_x), y(_y), val(_val){};     bool operator<(const node &b) const { return val < b.val; }   };   int calc(int x, int y) {     int x_lb = max(0, x - r + 1), x_ub = min(n - 1, x + r - 1);     int y_lb = max(0, y - r + 1), y_ub = min(m - 1, y + r - 1);     int res = (x_ub - x_lb + 2 - r) * (y_ub - y_lb + 2 - r);     if (res <= 0) {       cout <<  x  <<  =  << x <<   ,  , cout <<  y  <<  =  << y <<   ,  ,           cout <<  y_lb  <<  =  << y_lb <<   ,  ,           cout <<  r  <<  =  << r <<   ,  , cout <<  y_ub  <<  =  << y_ub << endl;     }     return res;   }   void solve() {     priority_queue<node> q;     int tmp = calc(n / 2, m / 2);     q.push(node(n / 2, m / 2, tmp));     rec.insert(make_pair(n / 2, m / 2));     double res = 0;     while (!q.empty() && k--) {       node cur = q.top();       q.pop();       res += cur.val;       for (int i = 0; i < (4); ++i) {         int tx = dir[0][i] + cur.x, ty = dir[1][i] + cur.y;         if (tx > -1 && ty > -1 && tx < n && ty < m &&             !rec.count(pair<int, int>(tx, ty))) {           rec.insert(pair<int, int>(tx, ty));           q.push(node(tx, ty, calc(tx, ty)));         }       }     }     double ans = res / (n - r + 1) / (m - r + 1);     printf( %.10lf n , ans);   }   int main() {     cin >> n >> m >> r >> k;     solve();   }
#include<bits/stdc++.h>   #define int long long int   #define pb push_back   #define all(x)  (x).begin(), (x).end()   using namespace std;       int solve(int a,int b)   {     if(a<=0)       return 0;     return min(1+solve(a/b,b), 2+solve(a/(b+1),b+1));   }    signed main()   {     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);     int t;     cin>>t;     while(t--)     {       int a,b;       cin>>a>>b;       int ans=1e9;       for(int i=0;i<100;i++)       {         int x=b+i;         int temp= i;         int xa=a;         int xb=x;         for(int j=0;j<100;j++)         {           if(xa<=0)             break;           xa/=xb;           temp++;         }          ans=min(ans,temp);       }       cout<<ans<<endl;     }   }
#include <bits/stdc++.h>   using namespace std;   inline int nxt() {     int x;     scanf( %d , &x);     return x;   }   using ld = long double;   int main() {     mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());     int n = nxt();     long long k;     scanf( %lld , &k);     vector<int> a(n);     for (int i = 0; i < n; ++i) {       a[i] = nxt();     }     ld r = 0;     ld l = 0;     for (int i = 0; i < n; ++i) {       r = max<ld>(r, a[i]);       l = min<ld>(l, a[i] - 3ll * a[i] * a[i]);     }     for (int it = 0; it < 300; ++it) {       ld m = (l + r) / 2;       ld sum = 0;       for (int i = 0; i < n; ++i) {         if (m > a[i]) {           continue;         }         if (m < a[i] - 3ll * a[i] * a[i]) {           sum += a[i];           continue;         }         sum += sqrtl((a[i] - m) / 3);       }       if (sum >= k) {         l = m;       } else {         r = m;       }     }     vector<int> b(n);     vector<pair<long long, int>> can;     ld m = (l + r) / 2;     long long ans = 0;     for (int i = 0; i < n; ++i) {       if (m > a[i]) {         continue;       }       if (m < a[i] - 3ll * a[i] * a[i]) {         k -= a[i];         b[i] = a[i];         ans += 1ll * b[i] * (a[i] - 1ll * b[i] * b[i]);         continue;       }       b[i] = sqrtl((a[i] - m) / 3);       k -= b[i];       ans += 1ll * b[i] * (a[i] - 1ll * b[i] * b[i]);       if (b[i] < a[i]) {         can.push_back({1ll * (b[i] + 1) * (a[i] - 1ll * (b[i] + 1) * (b[i] + 1)) -                            1ll * b[i] * (a[i] - 1ll * b[i] * b[i]),                        i});       }     }     sort((can).begin(), (can).end());     while (k) {       ans += can.back().first;       b[can.back().second] += 1;       can.pop_back();       --k;     }     cerr << ans <<   n ;     for (int x : b) {       cout << x <<    ;     }     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     cin.tie(0);     cin.sync_with_stdio(0);     int n;     cin >> n;     vector<string> a(2 * n - 2);     map<string, vector<int>> m;     for (int i = 0; i < 2 * n - 2; ++i) {       cin >> a[i];       m[a[i]].emplace_back(i);     }     int x = -1, y = -1;     for (int i = 0; i < 2 * n - 2; ++i) {       auto const& s = a[i];       if ((int)s.size() == n - 1) {         if (x == -1)           x = i;         else           y = i;       }     }     string ans(2 * n - 2,  S );     string u = a[x];     string v = a[y];     map<string, int> cc1, cc2;     for (int i = 0; i + 1 < n; ++i) {       ++cc1[u.substr(0, i + 1)];       ++cc1[v.substr(i, n - 1 - i)];       ++cc2[v.substr(0, i + 1)];       ++cc2[u.substr(i, n - 1 - i)];     }     bool can1 = true;     bool can2 = true;     for (auto const& [x, f] : m) {       can1 &= (cc1[x] == int(f.size()));       can2 &= (cc2[x] == int(f.size()));     }     if (not can1) {       swap(cc1, cc2);       swap(u, v);     }     for (int i = 0; i + 1 < n; ++i) {       auto p1 = u.substr(0, i + 1);       auto s1 = v.substr(i, n - 1 - i);       int idx1 = m[p1].back();       m[p1].pop_back();       int idx2 = m[s1].back();       m[s1].pop_back();       ans[idx1] =  P ;       ans[idx2] =  S ;     }     cout << ans;   }
#include <bits/stdc++.h>   using std::make_pair;   using std::pair;   const int N = 3e5 + 1e3;   int n, k;   int tot, rt;   struct Pair {     int l, r, pos, v1;     bool operator<(const Pair m) const { return v1 > m.v1; }   } p1[N], p2[N];   int sum[N << 4], ls[N << 4], rs[N << 4], mn[N << 4];   int r[N], a[N], mx[N], ans[N];   int ask(int cur, int l, int r, int L, int R) {     if (!cur) return 0;     if (L <= l && r <= R) {       return sum[cur];     }     int mid = l + r >> 1;     int ans = 0;     if (L <= mid) ans += ask(ls[cur], l, mid, L, R);     if (R > mid) ans += ask(rs[cur], mid + 1, r, L, R);     return ans;   }   int get(int cur, int l, int r, int L, int R) {     if (!cur) return 0;     if (L <= l && r <= R) {       return mn[cur];     }     int mid = l + r >> 1;     int ans = 0;     if (L <= mid) ans = std::max(ans, get(ls[cur], l, mid, L, R));     if (R > mid) ans = std::max(ans, get(rs[cur], mid + 1, r, L, R));     return ans;   }   void add(int &cur, int l, int r, int x, int v) {     if (!cur) cur = ++tot;     if (l == r) {       sum[cur] += v;       mn[cur] = std::max(mn[cur], v);       return;     }     int mid = l + r >> 1;     if (x <= mid)       add(ls[cur], l, mid, x, v);     else       add(rs[cur], mid + 1, r, x, v);     sum[cur] = sum[ls[cur]] + sum[rs[cur]];     mn[cur] = std::max(mn[ls[cur]], mn[rs[cur]]);   }   int main() {     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; ++i) scanf( %d , &r[i]);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (int i = 1; i <= n; ++i) {       p1[i].v1 = r[i], p1[i].l = a[i], p1[i].pos = i;     }     std::sort(p1 + 1, p1 + 1 + n);     std::reverse(p1 + 1, p1 + 1 + n);     for (int i = 1; i <= n; ++i) {       add(rt, 1, 1e9 + 2, p1[i].l, 1);       mx[p1[i].pos] = ask(rt, 1, 1e9 + 2, std::max(1, p1[i].l - k),                           std::min(p1[i].l + k, (int(1e9)) + 2));     }     int q;     scanf( %d , &q);     memset(ls, 0, sizeof(ls));     memset(rs, 0, sizeof(rs));     memset(sum, 0, sizeof(sum));     rt = tot = 0;     memset(mn, 0, sizeof(mn));     for (int i = 1; i <= q; ++i) {       int l, r;       scanf( %d %d , &l, &r);       p2[i].l = l, p2[i].r = r, p2[i].pos = i,       p2[i].v1 = std::max(::r[l], ::r[r]);     }     std::sort(p2 + 1, p2 + 1 + q);     std::sort(p1 + 1, p1 + 1 + n);     int now = 1;     for (int i = 1; i <= q; ++i) {       while (p2[i].v1 <= p1[now].v1 && now <= n) {         add(rt, 1, 1e9 + 1, a[p1[now].pos], mx[p1[now].pos]);         now++;       }       if (abs(a[p2[i].l] - a[p2[i].r]) > 2 * k) {         ans[p2[i].pos] = 0;         continue;       }       ans[p2[i].pos] = get(           rt, 1, 1e9 + 1, std::max(1, std::max(a[p2[i].l] - k, a[p2[i].r] - k)),           std::min((int(1e9)), std::min(a[p2[i].l] + k, a[p2[i].r] + k)));     }     for (int i = 1; i <= q; ++i) printf( %d  , ans[i] <= 0 ? -1 : ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long i, j, t, n, m, l, r, k, z, y, x;   long long a, b, ans;   int main() {     scanf( %I64d%I64d%I64d , &t, &a, &b);     if (t == 1) {       if (a == 1) {         if (a == b)           printf( inf n );         else           printf( 0 n );         return 0;       } else if (b >= a) {         while (b % a == 0) b /= a;         if (b == 1) {           printf( 1 n );           return 0;         }       }     }     ans = (a == b) ? 1 : 0;     x = z = 0;     y = 1;     if (t <= a) {       while (b) {         x = b % a;         b /= a;         z += y * x;         y *= t;       }     }     if (z == a) ans++;     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long k, b, n, t, z = 1, cnt = 0;     cin >> k >> b >> n >> t;     while (z <= t) {       cnt++;       z = k * z + b;     }     cout << n - min(n, cnt - 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   int n, m, k, t;   long long cnm[N];   long long h[N], w[N], e[N], ne[N], idx;   vector<long long> g[N];   int vis[N];   long long ans;   vector<int> res;   void add(int a, int b) { e[idx] = b, ne[idx] = h[a], h[a] = idx++; }   void dfs(int u, int s) {     if (s == 1) {       if (cnm[u] >= 0) {         ans += cnm[u];         res.push_back(u);         vis[u] = true;         for (int i = h[u]; i != -1; i = ne[i]) {           int j = e[i];           cnm[j] += cnm[u];           dfs(j, 2);         }       } else {         vis[u] = true;         for (int i = h[u]; i != -1; i = ne[i]) {           int j = e[i];           dfs(j, 2);         }         ans += cnm[u];         res.push_back(u);       }     } else {       bool ok = true;       for (auto it : g[u]) {         if (!vis[it]) {           ok = false;           dfs(it, 2);         }       }       if (ok) {         dfs(u, 1);       }     }   }   void solve() {     memset(h, -1, sizeof(h));     cin >> n;     for (int i = 1; i <= n; i++) cin >> cnm[i];     for (int i = 1; i <= n; i++) {       int a;       cin >> a;       if (a == -1) continue;       add(i, a);       g[a].push_back(i);     }     for (int i = 1; i <= n; i++) {       if (!vis[i] && g[i].size() == 0) {         dfs(i, 2);       }     }     cout << ans << endl;     for (auto it : res) cout << it <<    ;   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int a, b, c;     cin >> a >> b >> c;     long long int temp1, temp2, temp3;     temp1 = a / c;     temp2 = b / c;     if (a % c != 0) temp1++;     if (b % c != 0) temp2++;     cout << temp1 * temp2 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 45;   int n, m;   char G[maxn][maxn];   int sg[maxn][maxn][maxn][maxn][2];   int SG(int x0, int x1, int y0, int y1, int d) {     int &g = sg[x0][x1][y0][y1][d];     if (g != -1) return g;     char s[maxn * 2 + 1];     memset(s, 0, sizeof(s));     for (int y = 0; y < n; ++y) {       for (int x = 0; x < m; ++x) {         if (((x + y) & 1) == d) {           int x_ = y + x, y_ = y - x + m;           if (x0 <= x_ && x_ < x1 && y0 <= y_ && y_ < y1) {             int tmp;             if (G[y][x] ==  L )               tmp = SG(x0, x_, y0, y1, d) ^ SG(x_ + 1, x1, y0, y1, d);             if (G[y][x] ==  R )               tmp = SG(x0, x1, y0, y_, d) ^ SG(x0, x1, y_ + 1, y1, d);             if (G[y][x] ==  X ) {               tmp = SG(x0, x_, y0, y_, d) ^ SG(x0, x_, y_ + 1, y1, d) ^                     SG(x_ + 1, x1, y0, y_, d) ^ SG(x_ + 1, x1, y_ + 1, y1, d);             }             s[tmp] = 1;           }         }       }     }     while (s[++g])       ;     return g;   }   int main() {     while (cin >> n >> m) {       for (int i = 0; i < n; ++i) cin >> G[i];       memset(sg, -1, sizeof sg);       if ((SG(0, n + m, 0, n + m, 0) ^ SG(0, n + m, 0, n + m, 1)) > 0)         printf( WIN n );       else         printf( LOSE n );     }     return 0;   }
#include<bits/stdc++.h>      typedef   long long  int ll;   typedef  long double ld;   typedef std::vector<ll> vi;   typedef std::vector<std::vector<ll> > vv;   typedef std::vector<std::pair<ll,ll> > pii;      #define mod 1000000007   #define IO ios_base::sync_with_stdio(false);cin.tie(NULL);   #define fo(i,a,b) for(i=a;i<b;i++)   #define forr(i,a,b) for(i=a;i>=b;i--)   #define mp make_pair   #define pb(x) push_back(x)   #define fi first   #define se second   #define print(vec,a,b) for(ll i=a;i<b;i++) cout<<vec[i]<<   ;cout<<endl;   #define all(a) a.begin(),a.end()   #define input(vec,a,b) for(ll i = a;i<b;i++) cin>>vec[i];   #define ms(a,val) memset(a,val,sizeof(a))   using namespace std;      const int N = 2e5+ 5;            ll expo_pow(ll x, ll y) {    if (y == 0)     return 1;    y = y % (mod - 1);    x %= mod;    if (y == 0)     y = mod - 1;    ll res = 1;    while (y) {     if (y & 1)      res = (res * x) % mod;     x = (x * x) % mod;     y >>= 1;    }    return res;   }       ll modInverse(ll a, ll m = mod) {    return expo_pow(a, m - 2);   }             void solve(){               ll i,j,n,m;                              ll a,b,d;               cin>>a>>b>>d;                              if(a > b)               {       if((1 + d)*b >= a)        cout<< YES <<endl;       else        cout<< NO <<endl;       }       else if(b > a)                 {       if((1 + d)*a >= b)        cout<< YES <<endl;       else        cout<< NO <<endl;       }       else        cout<< YES <<endl;                                                                                                                                                                                                                               }            int main()   {        IO;         ll t=1,i;         cin>>t;                 while(t--)         {                solve();         }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, l, q, num, ll;     cin >> n >> m >> l;     vector<long long> len(n);     vector<bool> is_long(n, false);     long long prev_long = 0;     long long count = 0;     bool was_long = false;     for (long long i = 0; i < n; ++i) {       cin >> len[i];       if (len[i] > l) {         if (!was_long) {           ++count;         }         was_long = true;         is_long[i] = true;       } else {         was_long = false;       }     }     int c_merged;     for (long long i = 0; i < m; ++i) {       cin >> q;       if (q == 1) {         cin >> num >> ll;         len[num - 1] += ll;         if (len[num - 1] > l) {           c_merged = 0;           if (is_long[num - 1] == false) {             if (num - 2 >= 0 && is_long[num - 2] == true) {               c_merged++;             }             if (num < n && is_long[num] == true) {               c_merged++;             }             if (c_merged == 2) {               --count;             }             if (c_merged == 0) {               ++count;             }           }           is_long[num - 1] = true;         }       } else {         cout << count << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     string s;     cin >> s;     for (int i = 0; i < (int)s.size(); i++) {       if (s[i] ==  . )         cout <<  0 ;       else {         if (s[i + 1] ==  . )           cout <<  1 ;         else           cout <<  2 ;         i++;       }     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1009;   int a, b, sum = 0;   int arr[N][N], ans[N];   void llop_over(int r, int c) {     for (int i = 0; i < r; ++i) {       for (int g = 0; g < c; ++g) scanf( %d , &arr[i][g]);       sum ^= arr[i][0];     }   }   int main() {     scanf( %d %d , &a, &b);     llop_over(a, b);     if (sum == 0) {       bool flag = 0;       for (int i = 0; i < a && !flag; ++i) {         for (int g = 0; g < b; ++g) {           if (arr[i][g] != arr[i][0]) {             ans[i] = g;             flag = true;             break;           }         }       }       if (!flag) {         puts( NIE );         return 0;       }     }     cout <<  TAK n ;     for (int i = 0; i < a; ++i) cout << ans[i] + 1 <<    ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     char arr[1000];     cin >> arr;     int flag = 1, curr = 0;     for (int i = 0; i < strlen(arr); i++) {       if (i == 0)         curr = 1;       else if (flag == 1) {         if (arr[i] == arr[i - 1]) {           curr++;           if (curr >= 7) {             flag = 0;             cout <<  YES ;             return 0;           }         } else {           curr = 1;         }       }     }     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int sf[26][200005], tf[26][200005];   int main() {     long long int n, i, j;     cin >> n;     double ans = 0.0;     string s, t;     cin >> s >> t;     for (i = 0; i < n; ++i) {       sf[s[i] -  A ][i] += (i + 1);       tf[t[i] -  A ][i] += (i + 1);       if (i)         for (j = 0; j < 26; ++j) {           sf[j][i] += sf[j][i - 1];           tf[j][i] += tf[j][i - 1];         }       ans = ans + (n - i) * ((i ? sf[t[i] -  A ][i - 1] : 0) + tf[s[i] -  A ][i]);     }     ans = (6 * ans) / (n * (n + 1) * (2 * n + 1));     cout << fixed << setprecision(8) << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200000 + 10;   long long a[maxn], b[maxn], c[maxn];   int num[64];   int n;   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) cin >> b[i];     for (int i = 0; i < n; i++) cin >> c[i];     long long sum = 0;     for (int i = 0; i < n; i++) {       a[i] = b[i] + c[i];       sum += a[i];     }     if (sum % (2 * n)) {       cout << -1 << endl;       return 0;     }     sum /= 2 * n;     for (int i = 0; i < n; i++) {       a[i] = (a[i] - sum);       if (a[i] % n) {         cout << -1 << endl;         return 0;       } else {         a[i] /= n;       }     }     for (int i = 0; i < n; i++) {       long long temp = a[i];       for (int j = 0; j < 64; j++) {         num[j] += temp % 2;         temp /= 2;       }     }     for (int i = 0; i < n; i++) {       long long b_ = 0, c_ = 0;       for (int j = 0; j < 64; j++) {         if (a[i] & (1LL << j)) {           b_ += num[j] * (1LL << j);           c_ += n * (1LL << j);         } else           c_ += num[j] * (1LL << j);       }       if (b_ != b[i] || c_ != c[i]) {         cout << -1 << endl;         return 0;       }     }     cout << a[0];     for (int i = 1; i < n; i++) {       cout <<     << a[i];     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       vector<long long int> v(n, 0);       priority_queue<pair<long long int, pair<long long int, long long int>>> pq;       pq.push({n, {0, n - 1}});       long long int count = 0;       while (!pq.empty()) {         long long int l = -1 * pq.top().second.first;         long long int r = pq.top().second.second;         long long int length = pq.top().first;         pq.pop();         if (l > r) {           continue;         }         count++;         long long int mid = (l + r) / 2;         v[mid] = count;         pq.push({mid - l + 1, {(-1 * l), mid - 1}});         pq.push({r - mid + 1, {-1 * (mid + 1), r}});       }       for (auto it : v) {         cout << it <<    ;       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   bool isPal(string s) {     for (long long i = 0, j = s.length() - 1; i < j; i++, j--)       if (s[i] != s[j]) return 0;     return 1;   }   string lts111(long long n) {     string a =  00:00 ;     long long hr = n / 60;     long long min = n % 60;     long long fh = hr % 10;     hr = hr / 10;     a[0] = hr + 48;     a[1] = fh + 48;     fh = min % 10;     min = min / 10;     a[3] = min + 48;     a[4] = fh + 48;     return a;   }   long long stl111(string s) {     long long hr = (s[0] - 48) * 10 + (s[1] - 48);     long long min = (s[3] - 48) * 10 + (s[4] - 48);     return hr * 60 + min;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     string s;     cin >> s;     long long m = stl111(s);     m = m + 1;     while (1) {       m = m % 1440;       s = lts111(m);       if (isPal(s)) {         cout << s << endl;         return 0;       }       m = m + 1;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int ans = 0;     int temp;     stack<int> st;     for (int i = 0; i < n; ++i) {       cin >> temp;       while (!st.empty() && st.top() < temp) {         ans = max(ans, (st.top() ^ temp));         st.pop();       }       if (!st.empty()) ans = max(ans, (st.top() ^ temp));       st.push(temp);     }     temp = st.top();     st.pop();     while (!st.empty()) {       ans = max(ans, (st.top() ^ temp));       temp = st.top();       st.pop();     }     cout << ans, cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int fastExpo(long long int a, long long int n, long long int mod) {     long long int result = 1;     while (n > 0) {       if (n & 1) result = (result * a) % mod;       a = (a * a) % mod;       n >>= 1;     }     return result;   }   long long int modInverse(long long int n, long long int mod) {     return fastExpo(n, mod - 2, mod);   }   vector<long long int> factorial(long long int n) {     std::vector<long long int> fac(n + 2, 0);     fac[0] = 1;     for (long long int i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % 1000000007;     return fac;   }   long long int __nCr(long long int n, long long int r,                       vector<long long int>& Fact, long long int mod) {     long long int ans = (((Fact[n] * modInverse(Fact[r], mod)) % mod) *                          modInverse(Fact[n - r], mod)) %                         mod;     return ans;   }   void runcases(long long int T) {     string s, p;     cin >> s >> p;     s = p +  #  + s;     long long int n = s.size();     long long int m = p.size();     long long int count = 0;     vector<long long int> lps(n, 0);     long long int j = 0;     for (long long int i = 1; i < n; i++) {       j = lps[i - 1];       while (j > 0 && s[i] != s[j]) {         j = lps[j - 1];       }       if (s[i] == s[j]) {         j++;       }       lps[i] = j;       if (lps[i] == m) {         s[i] =  * ;         count++;         lps[i] = 0;       }     }     cout << count <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int T = 1;     for (long long int t = 1; t <= T; t++) {       runcases(t);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> num, sum;   int NUM[1005], Ind[1005];   int Set[1005];   int Top_sort(int n, int m) {     queue<int> q;     int i, j, ret;     for (i = 1; i <= n; i++)       if (Ind[i] == 0) q.push(i);     while (!q.empty()) {       i = q.front(), q.pop();       int now = 0, tab = 0;       for (j = i; true; j = NUM[j]) {         if (j == m) tab = 1, now = 0;         if (now++, NUM[j] == 0) break;       }       if (tab == 0)         num.push_back(now);       else         ret = now;     }     return ret;   }   int main() {     int n, m, i, j;     for (i = 1, scanf( %d%d , &n, &m); i <= n; i++)       if (scanf( %d , &NUM[i]), NUM[i]) Ind[NUM[i]]++;     int ans = Top_sort(n, m), end = 0;     Set[0] = 1;     for (i = 0; i < num.size(); i++)       for (j = end; j >= 0; j--)         if (Set[j]) Set[j + num[i]] = 1, end = max(end, j + num[i]);     for (j = 0; j <= end; j++)       if (Set[j]) printf( %d n , ans + j);     return 0;   }