<p>We define <code>str = [s, n]</code> as the string <code>str</code> which consists of the string <code>s</code> concatenated <code>n</code> times.</p>

<ul>
	<li>For example, <code>str == [&quot;abc&quot;, 3] ==&quot;abcabcabc&quot;</code>.</li>
</ul>

<p>We define that string <code>s1</code> can be obtained from string <code>s2</code> if we can remove some characters from <code>s2</code> such that it becomes <code>s1</code>.</p>

<ul>
	<li>For example, <code>s1 = &quot;abc&quot;</code> can be obtained from <code>s2 = &quot;ab<strong><u>dbe</u></strong>c&quot;</code> based on our definition by removing the bolded underlined characters.</li>
</ul>

<p>You are given two strings <code>s1</code> and <code>s2</code> and two integers <code>n1</code> and <code>n2</code>. You have the two strings <code>str1 = [s1, n1]</code> and <code>str2 = [s2, n2]</code>.</p>

<p>Return <em>the maximum integer </em><code>m</code><em> such that </em><code>str = [str2, m]</code><em> can be obtained from </em><code>str1</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> s1 = "acb", n1 = 4, s2 = "ab", n2 = 2
<strong>Output:</strong> 2
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> s1 = "acb", n1 = 1, s2 = "acb", n2 = 1
<strong>Output:</strong> 1
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= s1.length, s2.length &lt;= 100</code></li>
	<li><code>s1</code> and <code>s2</code> consist of lowercase English letters.</li>
	<li><code>1 &lt;= n1, n2 &lt;= 10<sup>6</sup></code></li>
</ul>

#pragma GCC optimize("unroll-loops,O3,Ofast") //even 10^8+ also works with this
#pragma GCC target("avx2,avx,fma,bmi,bmi2,lzcnt,popcnt")
typedef long long ll;

#define pb push_back
#define ppb pop_back
#define ff first
#define ss second
#define rt return;
#define set_bits(a) __builtin_popcountll(a)
#define mine(a)    (*min_element((a).begin(), (a).end()))
#define maxe(a)    (*max_element((a).begin(), (a).end()))
#define mini(a)    ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a)    ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define disp(a) {for(int i=0;i<a.size();i++) cout<<a[i]<<" "; cout<<endl;}
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define inp(a) {for(int i=0;i<(a).size();i++) cin>>(a)[i];}
#define fill(a,b) memset(a, b, sizeof(a))
#define prt(a) cout<<(a)<<endl;
#define endl "\n"
#define NO cout<<"NO"<<endl;
#define YES cout<<"YES"<<endl;
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define double double
#define de(a) cout<<"("<<a<<")"<<endl;
#define de2(a) cout<<"*"<<a<<"*"<<endl;
#define ft front()
#define bk back()
#define nl cout<<endl;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define cont continue;
#define vpll vector<pair<ll,ll>>
#define vvii vector<vi>
#define vi vector<int>
#define vvpll vector<vector<pair<ll,ll>>>
#define pll pair<ll,ll>
#define ld long double

template<class T> using minpq = priority_queue<T,vector<T>,greater<T>>;
template<class T> using maxpq = priority_queue<T>;

//const ll M=998244353;
const ll M=1e9+7;
const ll N=14;  
const ll inf=1e9; //keeping inf may not give soln every time,try 1e9, 1e15

bool isOverflow(ll x, ll y){return (x > LLONG_MAX / y or y > LLONG_MAX / x);}
ll bit(ll n,ll i){return (n&(1LL<<i)) ? 1 : 0;}
void unset(ll &n,ll i){ if((n&(1LL<<i))!=0) n-=(1LL<<i);}
void makeset(ll &n,ll i){ if((n&(1LL<<i))==0) n+=(1LL<<i);}
ll add(ll a,ll b){return ((a%M) + (b%M))%M;}
ll mul(ll a,ll b){return ((a%M) * (b%M))%M;}
ll sub(ll a,ll b){return ((a%M) - (b%M) + M)%M;}
ll isPail(string &s){string t=s; reverse(all(t)); return s==t; }

vll dx{-1,0,1,0},dy{0,-1,0,1};

class Solution {
public:
    int getMaxRepetitions(string s1, int n1, string s2, int n2) {
        ll n=s1.size(),m=s2.size();
        string s;
        for(int i=0;i<m;i++) s+=s1;
        s+=s1;
        vll dp(n,-1);
        for(int i=0;i<n;i++){
          ll ind=i,l=s.size(),c=0,ct=0;
          while(c<m && ind<s.size()){
            if(s[ind]==s2[c]) c++;
            ct++;
            ind++;
          }
          if(c==m){
            dp[i]=ct;           
          } 
          else return 0;
        }
        ll ct=0,ind=0,tot=0,ans=0;
        while(1){
          tot+=dp[ind];
          if(tot>n*n1) break;
          ll nxt=(dp[ind]+ind)%n;
          ct++;
          ind=nxt;
          ans=ct/n2;
        }
        return ans;
    }
};
8300