dp[i][j][k]表示前i个字符修改j个包含k个s2[1]的最优个数,不修改s1[i + 1]时更新dp[i + 1][j][k + s1[i + 1] == s2[1]],
修改时若更新为第一个更新dp[i + 1][j + 1][k + 1],否则更新dp[i + 1][j + 1][k + s2[1] == s2[2]]
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define se second
#define fi first
#define debug(x) cout<<#x<<" is "<<x<<endl
const int N = 200 + 5;
using namespace std;
typedef long long ll;
int dp[N][N][N];
typedef pair<int,int> pii;
int ans;
int n,t;
char s1[N],s2[N];
/*
int compute(string s,int pos,int change){
int cnt = 0;
if()s[pos] = s2[change];
for(int i = 0;i < s.size();i++){
if(s[i] != s2[0])
continue;
for(int j = i + 1;j <s.size();i++)
if(s[j] == s2[1])
cnt++;
}
return cnt;
}*/
#define dbg 0
const int INF = 0x3f3f3f3f;
int main(){
#if dbg
freopen("input.txt","r",stdin);
#endif
cin>>n>>t;
cin>>(s1 + 1)>>(s2 + 1);
for(int i = 0;i <N;i++)
for(int j = 0;j < N;j++)
for(int k = 0;k < N;k++)
dp[i][j][k] = -INF;
dp[0][0][0] = 0;
for(int i = 0;i < n;i++){
for(int j = 0;j <= min(i,t);j++){
for(int k = 0;k <= n;k++){
if(dp[i][j][k] == -INF)continue;
int e1 = (s1[i + 1] == s2[1]);
int e2 = (s1[i + 1] == s2[2]);
int e12 = (s2[1] == s2[2]);
dp[i + 1][j][k + e1] = max(dp[i + 1][j][k + e1],dp[i][j][k] + (e2?k:0));
if( j < t){
dp[i + 1][j + 1][k + 1] = max(dp[i + 1][j + 1][k + 1],dp[i][j][k] + (e12?k:0));
dp[i + 1][j + 1][k + e12] = max(dp[i + 1][j + 1][k + e12],dp[i][j][k] + k);
ans = max(max(dp[i + 1][j + 1][k + 1],dp[i + 1][j + 1][k + e12]),ans);
}
ans = max(dp[i + 1][j][k + e1],ans);
}
}
}
cout<<ans<<endl;
return 0;
}