Problem:
Score : 600 points

Problem Statement

Given are two strings s and t consisting of lowercase English letters. Determine if the number of non-negative integers i satisfying the following condition is finite, and find the maximum value of such i if the number is finite.

There exists a non-negative integer j such that the concatenation of i copies of t is a substring of the concatenation of j copies of s.

Notes

A string a is a substring of another string b if and only if there exists an integer x (0 \leq x \leq |b| - |a|) such that, for any y (1 \leq y \leq |a|), a_y = b_{x+y} holds.

We assume that the concatenation of zero copies of any string is the empty string. From the definition above, the empty string is a substring of any string. Thus, for any two strings s and t, i = 0 satisfies the condition in the problem statement.

Constraints

1 \leq |s| \leq 5 \times 10^5

1 \leq |t| \leq 5 \times 10^5

s and t consist of lowercase English letters.

Input

Input is given from Standard Input in the following format:

s
t

Output

If the number of non-negative integers i satisfying the following condition is finite, print the maximum value of such i; if the number is infinite, print -1.

Sample Input 1

abcabab
ab

Sample Output 1

3

The concatenation of three copies of t, ababab, is a substring of the concatenation of two copies of s, abcabababcabab, so i = 3 satisfies the condition.

On the other hand, the concatenation of four copies of t, abababab, is not a substring of the concatenation of any number of copies of s, so i = 4 does not satisfy the condition.

Similarly, any integer greater than 4 does not satisfy the condition, either. Thus, the number of non-negative integers i satisfying the condition is finite, and the maximum value of such i is 3.

Sample Input 2

aa
aaaaaaa

Sample Output 2

-1

For any non-negative integer i, the concatenation of i copies of t is a substring of the concatenation of 4i copies of s. Thus, there are infinitely many non-negative integers i that satisfy the condition.

Sample Input 3

aba
baaab

Sample Output 3

0

As stated in Notes, i = 0 always satisfies the condition.

Solution in C++14 (GCC 5.4.1) (judge verdict: Runtime Error)

/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
#define SZ 5000005
int len[SZ],fail[SZ];
bool can[SZ];
string s,t;
int ans[SZ];
void build(string &p){
	int len=p.size(),j=fail[0]=-1;
	for(int i=1;i<=len;i++){
		while(j>=0&&p[j]!=p[i-1])j=fail[j];
		fail[i]=++j;//if(p[fail[i]-1]==p[i-1])fail[i]=fail[fail[i]];
	}
}
bool kmp(string &_t,string &_s){
	int n=_t.size(),m=_s.size();
	for(int i=0,k=0;i<n;i++){
		while(k>=0&&_s[k]!=_t[i])k=fail[k];
		len[i]=++k;
		if(len[i]==m)can[i]=1;
		else can[i]=0;
	}
	return (*max_element(len,len+n))==m;
}
int main(){
	cin>>s>>t;
	const int size=2*((int)s.size()+t.size());
	while(s.size()<size){
		s=s+s;
	}
	s=s+s;
	build(t);
	kmp(s,t);
//	cerr<<s<<" "<<t<<endl;
//	for(int i=0;i<=s.size();i++){
//		cerr<<i<<" "<<fail[i]<<endl;
//	}
	for(int i=(int)s.size()-1;i>=0;i--){
		if(can[i]){
			ans[i-(int)t.size()+1]=max(ans[i-(int)t.size()+1],ans[i+1]+1);
		}
	}
	int final_ans=*max_element(ans,ans+(int)s.size()+1);
	if(final_ans>=(int)s.size()/t.size()-2){
		puts("-1");
		return 0;
	}
	cout<<final_ans<<endl;
	return 0;
}