//sort
#include<bits/stdc++.h>
#define int long long
#define lowbit(x) x&(-x)
using namespace std;
const int N=5e4+5;
int n,m,ans,v[N],w[N],f[N];
char s[N];
void put(int x,int y){
for(;x<=n;x+=lowbit(x))
f[x]+=y;
}
int get(int x){
int res=0;
for(;x;x-=lowbit(x))
res+=f[x];
return res;
}
bool cmp(int x,int y){
for(int l=1,i=x,j=y;l<=m;i++,j++,l++){
if((i>n)||(j>n)) return i>n;
else if(s[i]!=s[j]) return s[i]<s[j];
}
return x<y;
}
signed main(){
//freopen("sort.in", "r", stdin);
//freopen("sort.out", "w", stdout);
scanf("%lld%lld%s",&n,&m,s+1);
for(int i=1;i<=n;i++) v[i]=i;
sort(v+1,v+1+n,cmp);
for(int i=1;i<=n;i++) w[v[i]]=i;
for(int i=1;i<=n;i++)
ans+=get(n)-get(w[i]),put(w[i],1);
printf("%lld\n",ans);
return 0;
}