#include <bits/stdc++.h>
using namespace std;
int N, K, D[222][222][222];
char S[222], T[5];
int min(int a, int b) {
  if (a < b) return a;
  return b;
}
int max(int a, int b) {
  if (a > b) return a;
  return b;
}
int f(int i, int t0, int k) {
  if (D[i][t0][k] != -1) return D[i][t0][k];
  if (i >= N) return 0;
  int rtn = 0;
  if (k < K) {
    if (S[i] != T[0]) rtn = max(rtn, f(i + 1, t0 + 1, k + 1));
    if (S[i] != T[1]) rtn = max(rtn, f(i + 1, t0, k + 1) + t0);
  }
  rtn = max(rtn, f(i + 1, t0 + (S[i] == T[0]), k) + t0 * (S[i] == T[1]));
  D[i][t0][k] = rtn;
  return rtn;
}
int main() {
  cin >> N >> K >> S >> T;
  if (T[0] == T[1]) {
    int c = 0;
    for (int i = 0; S[i] != 0; i++) {
      if (S[i] == T[0]) c++;
    }
    c = min(strlen(S), c + K);
    cout << c * (c - 1) / 2;
    return 0;
  }
  for (int i = 0; i <= 200; i++)
    for (int j = 0; j <= 200; j++)
      for (int k = 0; k <= 200; k++) D[i][j][k] = -1;
  cout << f(0, 0, 0) << '\n';
  return 0;
}
