代码如下```
#include<bits/stdc++.h>
using namespace std;
int n, k, cnt;
queue q[21];
int main(){
cin >> n >> k;
for (int i=1; i<=n; i++){
string x;
cin >> x;
int s=x.size();
while (q[s-1].empty() == 0&&i-q[s-1].front()>k){
q[s-1].pop();
}
cnt += q[s-1].size();
q[s-1].push(i);
}
cout << cnt;
return 0;
}