#include<bits/stdc++.h>#define int long long#define pii pair<int, int>#define pb push_back#define mk make_pair#define F first#define S second#define ALL(x) x.begin(), x.end()usingnamespacestd;structHash{staticconstintM=998244353;staticconstintX=131;vector<int>H;vector<int>h;vector<int>pre;vector<int>inv;intn;Hash(string&s){n=s.size();H.resize(n);h.resize(n);pre.resize(n);inv.resize(n);H[0]=1;for(inti=0;i<n;i++){if(i)H[i]=(H[i-1]*X)%M;inv[i]=fastpow(H[i],M-2);}for(inti=0;i<n;i++){h[i]=((s[i]-'0'+1)*H[i])%M;if(i==0)pre[i]=h[i];elsepre[i]=(pre[i-1]+h[i])%M;}}intquery(intl,intr){if(l==0)returnpre[r];return((pre[r]-pre[l-1]+M)%M*inv[l])%M;}private:intfastpow(inta,intb){intret=1;while(b!=0){if(b&1)ret=ret*a%M;a=(a*a)%M;b>>=1;}returnret;}};signedmain(){strings;cin>>s;intn=s.size();s=s+s;HashS(s);intansL=0;for(inti=1;i<n;i++){// [i, i + n - 1]intl=0,r=n+1;while(r-l>1){intmid=(l+r)/2;if(S.query(i,i+mid-1)==S.query(ansL,ansL+mid-1)){l=mid;}else{r=mid;}}if(l==n)continue;if(s[i+l]<s[ansL+l]){ansL=i;}}cout<<s.substr(ansL,n)<<'\n';}
#include<bits/stdc++.h>#define int long long#define pii pair<int, int>#define pb push_back#define mk make_pair#define F first#define S second#define ALL(x) x.begin(), x.end()usingnamespacestd;structHash{staticconstintM=998244353;staticconstintX=131;vector<int>H;vector<int>h;vector<int>pre;vector<int>inv;intn;Hash(string&s){n=s.size();H.resize(n);h.resize(n);pre.resize(n);inv.resize(n);H[0]=1;for(inti=0;i<n;i++){if(i)H[i]=(H[i-1]*X)%M;inv[i]=fastpow(H[i],M-2);}for(inti=0;i<n;i++){h[i]=((s[i]-'0'+1)*H[i])%M;if(i==0)pre[i]=h[i];elsepre[i]=(pre[i-1]+h[i])%M;}}intquery(intl,intr){if(l==0)returnpre[r];return((pre[r]-pre[l-1]+M)%M*inv[l])%M;}private:intfastpow(inta,intb){intret=1;while(b!=0){if(b&1)ret=ret*a%M;a=(a*a)%M;b>>=1;}returnret;}};signedmain(){strings,t;cin>>s>>t;HashS(s),T(t);intcnt=0;for(inti=0;i<(int)s.size();i++){if(S.query(i,i+t.size()-1)==T.query(0,t.size()-1))cnt++;}cout<<cnt<<'\n';}
#include<bits/stdc++.h>#define int long long#define pii pair<int, int>#define pb push_back#define mk make_pair#define F first#define S second#define ALL(x) x.begin(), x.end()usingnamespacestd;structHash{staticconstintM=998244353;staticconstintX=131;vector<int>H;vector<int>h;vector<int>pre;vector<int>inv;intn;Hash(string&s){n=s.size();H.resize(n);h.resize(n);pre.resize(n);inv.resize(n);H[0]=1;for(inti=0;i<n;i++){if(i)H[i]=(H[i-1]*X)%M;inv[i]=fastpow(H[i],M-2);}for(inti=0;i<n;i++){h[i]=((s[i]-'0'+1)*H[i])%M;if(i==0)pre[i]=h[i];elsepre[i]=(pre[i-1]+h[i])%M;}}intquery(intl,intr){if(l==0)returnpre[r];return((pre[r]-pre[l-1]+M)%M*inv[l])%M;}private:intfastpow(inta,intb){intret=1;while(b!=0){if(b&1)ret=ret*a%M;a=(a*a)%M;b>>=1;}returnret;}};signedmain(){strings;cin>>s;HashS(s);intn=s.size();for(inti=1;i<n;i++){// [0, i - 1]// [n - i, n - 1]intl1=0,r1=i-1;intl2=n-i,r2=n-1;//if (l2 <= r1) break;if(S.query(l1,r1)==S.query(l2,r2)){cout<<i<<' ';}}}
#include<bits/stdc++.h>#define int long long#define pii pair<int, int>#define pb push_back#define mk make_pair#define F first#define S second#define ALL(x) x.begin(), x.end()usingnamespacestd;structHash{staticconstintM=998244353;staticconstintX=131;vector<int>H;vector<int>h;vector<int>pre;vector<int>inv;intn;Hash(string&s){n=s.size();H.resize(n);h.resize(n);pre.resize(n);inv.resize(n);H[0]=1;for(inti=0;i<n;i++){if(i)H[i]=(H[i-1]*X)%M;inv[i]=fastpow(H[i],M-2);}for(inti=0;i<n;i++){h[i]=((s[i]-'0'+1)*H[i])%M;if(i==0)pre[i]=h[i];elsepre[i]=(pre[i-1]+h[i])%M;}}intquery(intl,intr){if(l==0)returnpre[r];return((pre[r]-pre[l-1]+M)%M*inv[l])%M;}private:intfastpow(inta,intb){intret=1;while(b!=0){if(b&1)ret=ret*a%M;a=(a*a)%M;b>>=1;}returnret;}};signedmain(){strings;cin>>s;HashS(s);intn=s.size();for(inti=1;i<=n;i++){intfg=1;for(intj=i;j<n;j+=i){// [j, j + i - 1]intlen=min(i,(n-1)-j+1);if(S.query(0,len-1)!=S.query(j,j+len-1)){fg=0;break;}}if(fg)cout<<i<<'\n';}}