#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int a[n+1];
int ans = 0, dem = 0;
map<int, int> p;
for (int i = 1; i <= n; i++) {
string b;
cin >> b;
a[i]= b.size();
dem++;
if (dem > m+1) {
p[a[i-m-1]]--;
dem--;
}
ans -= (p[a[i]] * (p[a[i]] - 1)) / 2;
p[a[i]]++;
ans += (p[a[i]] * (p[a[i]] - 1)) / 2;
}
cout << ans << endl;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpIHsKICAgIGludCBuLCBtOwogICAgY2luID4+IG4gPj4gbTsKICAgIGludCBhW24rMV07CiAgICBpbnQgYW5zID0gMCwgZGVtID0gMDsKICAgIG1hcDxpbnQsIGludD4gcDsKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IG47IGkrKykgewogICAgICAgIHN0cmluZyBiOwogICAgICAgIGNpbiA+PiBiOwogICAgICAgIGFbaV09IGIuc2l6ZSgpOwogICAgICAgIGRlbSsrOwogICAgICAgIGlmIChkZW0gPiBtKzEpIHsKICAgICAgICAgICAgcFthW2ktbS0xXV0tLTsKICAgICAgICAgICAgZGVtLS07CiAgICAgICAgfQoKICAgICAgICBhbnMgLT0gKHBbYVtpXV0gKiAocFthW2ldXSAtIDEpKSAvIDI7CiAgICAgICAgcFthW2ldXSsrOwogICAgICAgIGFucyArPSAocFthW2ldXSAqIChwW2FbaV1dIC0gMSkpIC8gMjsKICAgIH0KICAgIGNvdXQgPDwgYW5zIDw8IGVuZGw7CiAgICByZXR1cm4gMDsKfQo=