#include <bits/stdc++.h>
using namespace std;
int f[205][205][205], n, K;
int ans = 0;
char s[205], t[205];
signed main(void) {
  scanf("%d%d", &n, &K);
  cin >> s + 1;
  cin >> t + 1;
  if (t[1] == t[2]) {
    int cnt = 0;
    for (int i = 1; i <= n; i++)
      if (s[i] == t[1]) cnt++;
    cnt += min(K, n - cnt);
    cout << cnt * (cnt - 1) / 2;
    return 0;
  }
  for (int i = 0; i <= 205 - 5; i++)
    for (int j = 0; j <= 205 - 5; j++)
      for (int k = 0; k <= 205 - 5; k++) f[i][j][k] = -1000000000;
  f[0][0][0] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= i; j++) {
      for (int k = 0; k <= min(i, K); k++) {
        if (s[i] == t[1]) {
          if (j) f[i][j][k] = max(f[i][j][k], f[i - 1][j - 1][k]);
          if (k) f[i][j][k] = max(f[i][j][k], f[i - 1][j][k - 1] + j);
        } else if (s[i] == t[2]) {
          if (j && k) f[i][j][k] = max(f[i][j][k], f[i - 1][j - 1][k - 1]);
          f[i][j][k] = max(f[i][j][k], f[i - 1][j][k] + j);
        } else {
          f[i][j][k] = max(f[i][j][k], f[i - 1][j][k]);
          if (k) {
            if (j) f[i][j][k] = max(f[i][j][k], f[i - 1][j - 1][k - 1]);
            f[i][j][k] = max(f[i][j][k], f[i - 1][j][k - 1] + j);
          }
        }
      }
    }
  }
  for (int j = 0; j <= n; j++)
    for (int k = 0; k <= K; k++) ans = max(ans, f[n][j][k]);
  cout << ans;
}
