#include <bits/stdc++.h>
using namespace std;
const int maxn = 205;
const int inf = 1e9 + 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 br = 0;
    for (int i = 1; i <= n; i++) br += (s[i] == t[1]);
    br = min(br + k, n);
    cout << br * (br - 1) / 2 << endl;
    return 0;
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= 200; j++) {
      for (int l = 0; l <= 200; l++) dp[i][j][l] = -inf;
    }
  }
  dp[0][0][0] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= k; j++) {
      for (int l = 0; l <= 200; l++) {
        dp[i][j][l] = dp[i - 1][j][l];
        if (s[i] == t[1]) {
          if (l >= 1) dp[i][j][l] = max(dp[i][j][l], dp[i - 1][j][l - 1]);
          if (j >= 1) dp[i][j][l] = max(dp[i][j][l], dp[i - 1][j - 1][l] + l);
          continue;
        }
        if (s[i] == t[2]) {
          dp[i][j][l] = max(dp[i][j][l], dp[i - 1][j][l] + l);
          if (j >= 1 && l >= 1)
            dp[i][j][l] = max(dp[i][j][l], dp[i - 1][j - 1][l - 1]);
          continue;
        }
        if (j >= 1 && l >= 1)
          dp[i][j][l] = max(dp[i][j][l], dp[i - 1][j - 1][l - 1]);
        if (j >= 1) dp[i][j][l] = max(dp[i][j][l], dp[i - 1][j - 1][l] + l);
      }
    }
  }
  long long rez = 0;
  for (int j = 0; j <= k; j++) {
    for (int l = 0; l <= 200; l++) rez = max(rez, dp[n][j][l]);
  }
  cout << rez << endl;
  return 0;
}
