Loading Similar Posts
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin >> s;
int n = s.length();
int k;
cin >> k;
int r = 1;
int ans = 0;
map<char, int> pre, suf;
for (int i = 0; i < n; i++)
{
suf[s[i]]++;
}
while (r < n - 1)
{
pre[s[r-1]]++;
if(suf[s[r-1]]==1) suf.erase(s[r-1]);
else suf[s[r-1]]--;
int x = 0;
for(auto it:pre){
if(suf.find(it.first)!=suf.end()) x++;
}
if(x>k) ans++;
r++;
}
cout<<ans<<endl;
}