#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 210;
int dp[maxn][maxn][maxn];
int aft[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  string ss, t;
  cin >> ss >> t;
  string s = '*' + ss;
  for (int i = s.length() - 1; i >= 1; --i)
    aft[i] = aft[i + 1] + (s[i] == t[1]);
  memset(dp, -0x3f, sizeof(dp));
  dp[0][0][0] = 0;
  int res = 0, same = t[0] == t[1];
  for (int i = 1; i < s.length(); ++i) {
    bool f = s[i] == t[0], sec = s[i] == t[1];
    for (int j = 0; j <= k && j <= i; ++j) {
      dp[i][j][0] = dp[i - 1][j][0];
      for (int l = 1; l <= i; ++l) {
        int ans = 0;
        if (f) {
          ans = dp[i - 1][j][l - 1] + aft[i + 1];
          if (!sec && j) ans = max(ans, dp[i - 1][j - 1][l] + l);
        } else if (sec) {
          ans =
              max(dp[i - 1][j][l],
                  j ? (dp[i - 1][j - 1][l - 1] - (l - 1) + aft[i + 1]) : -INF);
        } else {
          ans = dp[i - 1][j][l];
          if (j && !same)
            ans = max(ans, max(dp[i - 1][j - 1][l - 1] + aft[i + 1],
                               dp[i - 1][j - 1][l] + l));
          else if (j)
            ans = max(ans, dp[i - 1][j - 1][l - 1] + aft[i + 1] + l - 1);
        }
        dp[i][j][l] = ans;
        res = max(ans, res);
      }
    }
  }
  cout << res << '\n';
  return 0;
}
