#include <bits/stdc++.h>
#include <string>
using namespace std;
int n,m,ans=0;
string s;
struct node
{
int pos;
string s;
}a[50001];
int b[50001];
int c[50001];//树状数组闪亮登场
inline bool operator<(const node &nd,const node &nd2){
return nd.s<nd2.s;
}
inline const void add(int t)
{
while(t<=n)
{
c[t]++;
t+=t&(-t);
}
}
inline const int getsum(int t)
{
int i,sum=0;
while(t)
{
sum+=c[t];
t-=t&(-t);
}
return sum;
}
int main()
{
//freopen("sort2.in","r",stdin);
//freopen("sort.out","w",stdout);
int i;
scanf("%d %d",&n,&m);
cin>>s;
for(i=1;i<=n;i++)
a[i].s=s.substr(i-1,m),a[i].pos=i;
sort(a+1,a+n+1);
int p=1;
b[a[1].pos]=p;
for(i=2;i<=n;i++)
{
if(a[i-1].s!=a[i].s)
p++;
b[a[i].pos]=p;
}
//for(i=1;i<=n;i++)
//cout<<b[i]<<" ";
//cout<<endl;
for(i=1;i<=n;i++)
{
add(b[i]);
ans+=i-getsum(b[i]);
}
cout<<ans;
}