#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 5e4+5;
int c[maxn];
int len;
inline int lowbit(int x){return x&-x;}
inline void inc(int x){while(x<=len){c[x]++;x+=lowbit(x);}}
inline int sum(int x){int ret = 0;while(x){ret+=c[x];x-=lowbit(x);}return ret;}
struct str {
string s;
int index;
} arr[maxn];
int newa[maxn];
inline bool operator<(const str &s1,const str &s2){
return s1.s<s2.s;
}
int main() {
int n,m;
scanf("%d%d",&n,&m);
string s;
cin>>s;
len = n;
for(int i = 0; i<n; i++) {
arr[i+1].s = s.substr(i,m);
arr[i+1].index = i+1;
}
sort(arr+1,arr+1+len);
for(int i = 1;i<=len;i++){
int val;
if(arr[i].s!=arr[i-1].s){
val = i;
}else{
val = newa[arr[i-1].index];
}
arr[i].s.clear();
arr[i].s.shrink_to_fit();
newa[arr[i].index] = val;
}
long long ans = 0;
for(int i = 1;i<=len;i++){
inc(newa[i]);
ans+=i-sum(newa[i]);
}
cout<<ans;
return 0;
}