#include <bits/stdc++.h>
using namespace std;
int mod = -1e9;
const int maxn = 2e5 + 5;
int dist(int x, int y) { return x != y; }
int32_t main() {
  ios_base::sync_with_stdio(0);
  ;
  int n, k;
  cin >> n >> k;
  string s, t;
  cin >> s >> t;
  vector<int> v;
  for (auto it : s) {
    v.emplace_back(it - 'a');
  }
  int a = t[0] - 'a';
  int b = t[1] - 'a';
  vector<vector<int> > dp(n + 1, vector<int>(n + 1, mod));
  if (v[0] == a) {
    dp[0][1] = 0;
  } else {
    dp[1][1] = 0;
    dp[0][0] = 0;
  }
  for (int i = 1; i < n; ++i) {
    vector<vector<int> > newdp(n + 1, vector<int>(n + 1, mod));
    for (int ops = 0; ops < k + 1; ++ops) {
      for (int numberOfA = 0; numberOfA <= i + 1; ++numberOfA) {
        int &ans = newdp[ops][numberOfA];
        ans = dp[ops][numberOfA];
        if (a == b) {
          int d = dist(v[i], a);
          if (numberOfA and ops - d >= 0)
            ans = max(ans, dp[ops - d][numberOfA - 1] + numberOfA - 1);
        } else {
          int d = dist(v[i], a);
          if (numberOfA and ops - d >= 0)
            ans = max(ans, dp[ops - d][numberOfA - 1]);
          d = dist(v[i], b);
          if (ops - d >= 0) ans = max(ans, dp[ops - d][numberOfA] + numberOfA);
        }
      }
    }
    dp = newdp;
  }
  int ans = 0;
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j <= n; ++j) {
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans << '\n';
  ;
  return 0;
}
