#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<map>
#include<iomanip>
#include<cstring>
#define reg register
#define EN std::puts("")
#define LL long long
inline int read(){
register int x=0;register int y=1;
register char c=std::getchar();
while(c<'0'||c>'9'){if(c=='-') y=0;c=std::getchar();}
while(c>='0'&&c<='9'){x=x*10+(c^48);c=std::getchar();}
return y?x:-x;
}
#define N 100005
#define base 131
int n,m;
char s[N];
int a[N];
unsigned long long hash[N],power[N];
inline void work_hash(){
for(reg int i=1;i<=n;i++) hash[i]=hash[i-1]*base+s[i];
}
inline int cmp(int a,int b){
if(a==b) return 1;
if(s[a]^s[b]) return s[a]<s[b];
int lena=std::min(m,n-a+1),lenb=std::min(m,n-b+1);
reg int l=1,r=std::min(lena,lenb),mid,len;
while(l<=r){
mid=(l+r)>>1;
if(hash[a+mid-1]-hash[a-1]*power[mid]==hash[b+mid-1]-hash[b-1]*power[mid]) len=mid,l=mid+1;
else r=mid-1;
}
if(lena==lenb&&lena==len) return a<b;
if(lena==len) return 1;
if(lenb==len) return 0;
return s[a+len]<s[b+len];
}
struct tr{
tr *ls,*rs;
int x;
}dizhi[N*2],*root=&dizhi[0];
int tot;
inline void build(tr *tree,int l,int r){
if(l==r) return;
int mid=(l+r)>>1;
tree->ls=&dizhi[++tot];tree->rs=&dizhi[++tot];
build(tree->ls,l,mid);build(tree->rs,mid+1,r);
}
inline void change(tr *tree,int l,int r,int pos){
if(l==r) return tree->x++,void();
int mid=(l+r)>>1;
pos<=mid?change(tree->ls,l,mid,pos):change(tree->rs,mid+1,r,pos);
tree->x++;
}
inline int ask(tr *tree,int l,int r,int ql,int qr){
if(ql<=l&&r<=qr) return tree->x;
int mid=(l+r)>>1;
if(qr<=mid) return ask(tree->ls,l,mid,ql,qr);
if(ql>mid) return ask(tree->rs,mid+1,r,ql,qr);
return ask(tree->rs,mid+1,r,ql,qr)+ask(tree->ls,l,mid,ql,qr);
}
int main(){
// std::freopen("sort.in","r",stdin);
// std::freopen("sort.out","w",stdout);
n=read();m=read();
scanf("%s",s+1);
work_hash();
power[0]=1;
for(reg int i=1;i<=n;i++){
power[i]=power[i-1]*base;
a[i]=i;
}
std::sort(a+1,a+1+n,cmp);
// for(reg int i=1;i<=n;i++) printf("%d\n",a[i]);EN;
build(root,1,n);
change(root,1,n,a[1]);
long long ans=0;
for(reg int i=2;i<=n;i++){
if(a[i]^n) ans+=ask(root,1,n,a[i]+1,n);
change(root,1,n,a[i]);
}
printf("%lld\n",ans);
return 0;
}