#include <bits/stdc++.h>
using namespace std;
const int maxn = 205;
const long long inf = 1e18 + 5;
int n, k;
string s, t;
long long dp[maxn][maxn][maxn];
int main() {
  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);
  cin >> n >> k >> s >> t;
  s = ' ' + s;
  t = ' ' + t;
  if (t[1] == t[2]) {
    int len = 0;
    for (int i = 1; i <= n; i++) len += (s[i] == t[1]);
    len = min(n, len + k);
    cout << len * (len - 1) / 2 << endl;
    return 0;
  }
  for (int i = 0; i <= maxn - 1; i++) {
    for (int j = 0; j <= maxn - 1; j++) {
      for (int l = 0; l <= maxn - 1; l++) dp[i][j][l] = -inf;
    }
  }
  if (s[1] == t[1]) {
    dp[1][0][1] = 0;
  } else {
    dp[1][0][0] = 0;
    dp[1][1][1] = 0;
  }
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j <= maxn - 1; j++) {
      for (int l = 0; l <= maxn - 1; l++) {
        if (s[i] == t[1]) {
          dp[i][j][l + 1] = max(dp[i][j][l + 1], dp[i - 1][j][l]);
          dp[i][j + 1][l] = max(dp[i][j + 1][l], dp[i - 1][j][l] + l);
          continue;
        }
        if (s[i] == t[2]) {
          dp[i][j][l] = max(dp[i][j][l], dp[i - 1][j][l] + l);
          dp[i][j + 1][l + 1] = max(dp[i][j + 1][l + 1], dp[i - 1][j][l]);
          continue;
        }
        dp[i][j][l] = max(dp[i][j][l], dp[i - 1][j][l]);
        dp[i][j + 1][l] = max(dp[i][j + 1][l], dp[i - 1][j][l] + l);
        dp[i][j + 1][l + 1] = max(dp[i][j + 1][l + 1], dp[i - 1][j][l]);
      }
    }
  }
  long long rez = 0;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= maxn - 1; j++) rez = max(rez, dp[n][i][j]);
  }
  cout << rez << endl;
  return 0;
}
