#include <bits/stdc++.h>
using namespace std;
#define TLHAdepzais1tg ios_base::sync_with_stdio(0);cin.tie();cout.tie(0);
#define ll long long
#define N 1000007
#define fi first
#define se second
#define pii pair<ll,ll>
#define str string
ll n,k,pre[N],ans=0;
ll m[N];
string s;
int main()
{
    TLHAdepzais1tg;
    if(fopen("kastr.inp","r"))
    {
        freopen("kastr.inp","r",stdin);
        freopen("kastr.out","w",stdout);
    }
    cin>>n>>k;
    cin>>s;
    pre[0]=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='a')
            pre[i+1]=pre[i]+1;
        else
            pre[i+1]=pre[i];
    }
    for(int i=0;i<=n;i++)
    {
        ans+=m[pre[i]-k];
        m[pre[i]]++;
    }
    cout<<ans;
    return 0;
}

