C++ 代码
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
int k;
LL ans,res;
string s;
char a,b;
int main(){
cin >> k >> s >> a >> b;
int n = s.size();
for(int i = 0,j = k - 1; j < n; i++, j++)
{
if(s[i] == a) ans ++;
if(s[j] == b) res += ans;
}
cout << res;
}