int n,m,nxt[1000006]; char a[1000006],b[1000006]; intmain() { // ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); CI (a+1)>>(b+1); n=strlen(a+1); m=strlen(b+1); nxt[1]=0; int j=0; for (int i=2;i<=m;i++) { while (b[i]!=b[j+1]&&j>0) j=nxt[j]; if (b[i]==b[j+1]) { j++; nxt[i]=j; } }
j=0; for (int i=0;i<n;i++) { while (a[i+1]!=b[j+1]&&j>0) j=nxt[j]; if (a[i+1]==b[j+1]) j++; if (j==m) cout<<i+1-m+1<<endl; } for (int i=1;i<=m;i++) cout<<nxt[i]<<" "; cout<<endl; return0; }
int n,m,nxt[1000006],f[1000006]; char a[1000006],b[1000006],c[1000006];
intmain() { // ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); CI (a+1)>>(b+1); n=strlen(a+1); m=strlen(b+1); nxt[1]=0; int j=0; for (int i=2;i<=m;i++) { while (b[i]!=b[j+1]&&j>0) j=nxt[j]; if (b[i]==b[j+1]) { j++; nxt[i]=j; } }
int top=0; for (int i=0;i<n;i++) { c[++top]=a[i+1]; // cout<<top<<c[top]<<endl; while ((a[i+1]!=b[j+1])&&j>0) j=nxt[j];
if (a[i+1]==b[j+1]) j++; f[top]=j; if (j==m) top-=m,j=f[top]; } c[++top]='\0'; cout<<(c+1)<<endl; return0; }
int n,m,nxt[1000006],ans=0; char b[1000006]; intmain() { // ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); CI m; CI (b+1); m=strlen(b+1); nxt[1]=0; int j=0; for (int i=2;i<=m;i++) { while (b[i]!=b[j+1]&&j>0) j=nxt[j]; if (b[i]==b[j+1]) { j++; nxt[i]=j; } }
int t,a[200005],sum,n,avg,x,f; intmain() { // ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); CI t; while (t--) { sum=x=0; f=1; CI n; F(i,1,n) { CI a[i]; sum+=a[i]; } avg=sum/n; F(i,1,n) { if (a[i]+x>=avg) x=a[i]+x-avg; else { f=0; break; } } if (f) CO "YES" L; else CO "NO" L; } return0; }
int t,n,a[200005]; intmain() { ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); CI t; while (t--) { CI n; F(i,1,n) CI a[i]; int l1=a[1],l2=1,r1=a[n],r2=1; F(i,2,n) if (a[i]==l1) l2++; elsebreak; FD(i,n-1,1) if (a[i]==r1) r2++; elsebreak; if (l1==r1) CO max(0,n-l2-r2) L; else CO min(n-l2,n-r2) L; } return0; }
LL t,n,x,y,a,ans; intmain() { ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); CI t; while (t--) { ans=0; map<pair<LL,LL>,int> s; CI n>>x>>y; F(i,1,n) { CI a; if (s.find(make_pair((x-a%x)%x,a%y))!=s.end()) ans+=s.find(make_pair((x-a%x)%x,a%y))->second; if (s.find(make_pair(a%x,a%y))!=s.end()) s[make_pair(a%x,a%y)]++; else s.insert(make_pair(make_pair(a%x,a%y),1)); } CO ans L; } return0; }