Language: C++

//by xxj
//I love 7 sea k fall
#include<bits/stdc++.h>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ll long long
#define pii pair<int,int>
#define lowbit(x) x&-x
const int inf=1e9+7;
const double eps=1e-10;
const ll linf=1e18+7;
const ll hh=523;
//const int mod=;
inline int read(){
    int x=0;char ch=getchar();
    while(ch<'0'||ch>'9')ch=getchar();
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x;
}
string s1,s,t;
bool canbe[2000007];
int next[500007];
void find_next(){
	string q=t;
	q+='$';
	int i=0,j=-1;
	next[i]=j;
	while (i!=q.size()-1){
		if (j==-1 || q[i]==q[j]){
			if (q[++i]==q[++j]){
				next[i]=next[j];
			}
			else{
				next[i]=j;
			}
		}
		else{
			j=next[j];
		}
	}
//	for (int i=0;i<q.size();i++){
//		cout<<i<<' '<<next[i]<<endl;
//	}
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>s1>>t;
	s=s1;
	while (s.size()<t.size()){
		s+=s1;
	}
	s1=s; 
	s+=s1;
//	cout<<s<<' '<<s1<<endl;
	find_next();
//	puts("!!!!");
	int j=0;
	for (int i=0;i<s.size();i++){
//		cout<<i<<' '<<next[j]<<endl;
		while (j!=-1 && t[j]!=s[i]){
			j=next[j];
		}
//		cout<<i<<endl;
//		cout<<i<<' '<<j<<endl;
		j++;
//		cout<<i<<' '<<j<<endl;
		if (j==t.size()){
			canbe[i-t.size()+1]=true;
//			cout<<i-t.size()+1<<endl;
			j=next[j];
		}
	}
//	puts("");
	int ans=0,mx=0;
	int cnt=0;
	for (int i=0;i<s.size();i++){
		cnt=0;
		while (canbe[i]){
			cnt++;
			i=i+t.size(); 
		}
		ans=max(ans,cnt);
	}
	if (!ans){
		printf("%d\n",ans);
		return 0;
	}
	s+=s1;
	j=0;
	for (int i=0;i<s.size();i++){
//		cout<<i<<' '<<next[j]<<endl;
		while (j!=-1 && t[j]!=s[i]){
			j=next[j];
		}
//		cout<<i<<endl;
//		cout<<i<<' '<<j<<endl;
		j++;
//		cout<<i<<' '<<j<<endl;
		if (j==t.size()){
			canbe[i-t.size()+1]=true;
//			cout<<i-t.size()+1<<endl;
			j=next[j];
		}
	}
	for (int i=0;i<s.size();i++){
		cnt=0;
		while (canbe[i]){
			cnt++;
			i=i+t.size(); 
		}
		mx=max(mx,cnt);
	}
	if (mx>ans){
		puts("-1");
	}
	else{
		printf("%d\n",ans);
	}
	return 0;
}
/*
input:
*/


Compiler output:
a.cc: In function 'void find_next()':
a.cc:29:9: error: reference to 'next' is ambiguous
   29 |         next[i]=j;
      |         ^~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:66,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:24:5: note:                 'int next [500007]'
   24 | int next[500007];
      |     ^~~~
a.cc:33:33: error: reference to 'next' is ambiguous
   33 |                                 next[i]=next[j];
      |                                 ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:24:5: note:                 'int next [500007]'
   24 | int next[500007];
      |     ^~~~
a.cc:33:41: error: reference to 'next' is ambiguous
   33 |                                 next[i]=next[j];
      |                                         ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:24:5: note:                 'int next [500007]'
   24 | int next[500007];
      |     ^~~~
a.cc:36:33: error: reference to 'next' is ambiguous
   36 |                                 next[i]=j;
      |                                 ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:24:5: note:                 'int next [500007]'
   24 | int next[500007];
      |     ^~~~
a.cc:40:27: error: reference to 'next' is ambiguous
   40 |                         j=next[j];
      |                           ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:24:5: note:                 'int next [500007]'
   24 | int next[500007];
      |     ^~~~
a.cc: In function 'int main()':
a.cc:64:27: error: reference to 'next' is ambiguous
   64 |                         j=next[j];
      |                           ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:24:5: note:                 'int next [500007]'
   24 | int next[500007];
      |     ^~~~
a.cc:73:27: error: reference to 'next' is ambiguous
   73 |                         j=next[j];
      |                           ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:24:5: note:                 'int next [500007]'
   24 | int next[500007];
      |     ^~~~
a.cc:96:27: error: reference to 'next' is ambiguous
   96 |                         j=next[j];
      |                           ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:24:5: note:                 'int next [500007]'
   24 | int next[500007];
      |     ^~~~
a.cc:105:27: error: reference to 'next' is ambiguous
  105 |                         j=next[j];
      |                           ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:24:5: note:                 'int next [500007]'
   24 | int next[500007];
      |     ^~~~