using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; using System.Reflection; using static System.Math; using System.Numerics; static class Program{ const int mod=(int)1e9+7; const double eps=1e-11; static void Main(){ Sc sc=new Sc(); var s=sc.S; var n=sc.I; Sa sa=new Sa(s,'A','Z'); int ans=0; for(int i = 0;i(); int[] sub=new int[n]; int[] hi=new int[m]; int[] hc1=new int[m]; int[] hc2=new int[m]; int[] hc3=new int[m]; hi[s[n-1]-o]=hc2[s[n-1]-o]=hc3[s[n-1]-o]=1; for(int i = n-2,k=n-1;i>=0;i--) { h[i]=s[i]!=s[i+1]?(s[i]>s[i+1]?1:0):h[i+1]; hi[s[i]-o]++; if(h[i]==1&&h[i+1]==0){ h[i+1]=2; lms.Add(i+1); sub[i+1]=k-i; k=i+1; } } for(int i = 1;i0&&h[sa[i]-1]==1){ sa[hc1[s[sa[i]-1]-o]]=sa[i]-1; hc1[s[sa[i]-1]-o]++; } } for(int i = n-1;i>=0;i--) { if(sa[i]>0&&h[sa[i]-1]!=1){ hc3[s[sa[i]-1]-o]--; sa[hc3[s[sa[i]-1]-o]]=sa[i]-1; } } int[] lh=new int[c]; for(int i = 0,j=c-1;i=0;i++) { if(h[sa[i]]==2){lh[j]=sa[i];j--;} } int[] lmsz=new int[n]; int[] lmsc=new int[c]; bool jf=false; int ki=0; for(int i = c-2;i>=0;i--) { if(sub[lh[i]]==sub[lh[i+1]]){ bool bo=false; for(int j = 0;j=0;i--) {lmsc[c-i-1]=lmsz[lms[i]];} hc2[0]=hc3[0]=hi[0]; hc1[0]=0; for(int i = 1;i0&&h[sa[i]-1]==1){ sa[hc1[s[sa[i]-1]-o]]=sa[i]-1; hc1[s[sa[i]-1]-o]++; } } for(int i = n-1;i>=0;i--) { if(sa[i]>0&&h[sa[i]-1]!=1){ hc3[s[sa[i]-1]-o]--; sa[hc3[s[sa[i]-1]-o]]=sa[i]-1; } } } public int Fb(string t){return Bs1(t);} public Tuple Ft(string t){ int p=Bs1(t); return p==-1?Tuple.Create(-1,-2):Tuple.Create(p,Bs2(t)-1); } private int Bs1(string t){ int l=t.Length-1; int lb=-1,mid=0,ub=n-1; while(ub-lb>1){ mid=(ub+lb)/2; int ti=0; while(ti=t[ti]){ub=mid;} else{lb=mid;} } bool bo=true; for(int i = 0;i<=l;i++) {if(s[sa[ub]+i]!=t[i]){bo=false;break;}} return bo?ub:-1; } private int Bs2(string t){ int l=t.Length; int lb=-1,mid=0,ub=n; while(ub-lb>1){ mid=(ub+lb)/2; int tm=Min(l,n-sa[mid])-1,ti=0; while(s[sa[mid]+ti]==t[ti]&&tit[ti]){ub=mid;} else{lb=mid;} } return ub; } private int[] Fu2(IReadOnlyList s,int m){ int n=s.Count; var lms=new List(); int[] h=new int[n],sub=new int[n],sa=new int[n]; int[] hi=new int[m],hc1=new int[m],hc2=new int[m],hc3=new int[m]; hi[s[n-1]]=hc2[s[n-1]]=hc3[s[n-1]]=1; for(int i = n-2,k=n-1;i>=0;i--) { h[i]=s[i]!=s[i+1]?(s[i]>s[i+1]?1:0):h[i+1]; hi[s[i]]++; if(h[i]==1&&h[i+1]==0){ h[i+1]=2; lms.Add(i+1); sub[i+1]=k-i; k=i+1; } } int lm=lms.Count; for(int i = 1;i0&&h[sa[i]-1]==1){ sa[hc1[s[sa[i]-1]]]=sa[i]-1; hc1[s[sa[i]-1]]++; } } for(int i = n-1;i>=0;i--) { if(sa[i]>0&&h[sa[i]-1]!=1){ hc3[s[sa[i]-1]]--; sa[hc3[s[sa[i]-1]]]=sa[i]-1; } } int[] sl=new int[lm]; for(int i = 0,j=lm-1;i=0;i++) { if(h[sa[i]]==2){sl[j]=sa[i];j--;} } int[] lmsz=new int[n]; bool jf=false; int ki=0; for(int i = lm-2;i>=0;i--) { if(sub[sl[i]]==sub[sl[i+1]]){ bool bo=false; for(int j = 0;j=0;i--) {lmsc[lm-i-1]=lmsz[lms[i]];} hc2[0]=hc3[0]=hi[0]; hc1[0]=0; for(int i = 1;i=0;i--) { if(sa[i]>0&&h[sa[i]-1]==1){ sa[n-1-hc1[s[sa[i]-1]]]=sa[i]-1; hc1[s[sa[i]-1]]++; } } for(int i = 0;i0&&h[sa[i]-1]!=1){ hc3[s[sa[i]-1]]--; sa[n-1-hc3[s[sa[i]-1]]]=sa[i]-1; } } return sa; } } public class Sc{ public int I{get{return int.Parse(Console.ReadLine());}} public long L{get{return long.Parse(Console.ReadLine());}} public double D{get{return double.Parse(Console.ReadLine());}} public string S{get{return Console.ReadLine();}} public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}} public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}} public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}} public string[] Sa{get{return Console.ReadLine().Split();}} public object[] Oa{get{return Console.ReadLine().Split();}} public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}} public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);} public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);} public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}} public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);} public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);} public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}} public double[] Da3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),double.Parse);} public double[] Da3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),double.Parse);} public T[] Arr(int n,Func f){var a=new T[n];for(int i=0;i(int n,Func f){var a=new T[n];for(int i=0;i(int n,Func f){var a=new T[n];for(int i=0;i(int n,Func f){var a=new T[n];for(int i=0;i