#include <bits/stdc++.h>
using namespace std;
const int maxn = 210;
int n, k, ans, f[maxn][maxn][maxn];
string s, t;
int main() {
  cin >> n >> k >> s >> t;
  memset(f, -0x3f, sizeof(f));
  f[0][0][0] = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= k; ++j) {
      for (int l = 0; l <= i; ++l) {
        f[i + 1][j + 1][l + 1] =
            max(f[i + 1][j + 1][l + 1], f[i][j][l] + (t[0] == t[1]) * l);
        f[i + 1][j + 1][l + (t[0] == t[1])] =
            max(f[i + 1][j + 1][l + (t[0] == t[1])], f[i][j][l] + l);
        f[i + 1][j][l + (s[i] == t[0])] = max(f[i + 1][j][l + (s[i] == t[0])],
                                              f[i][j][l] + (s[i] == t[1]) * l);
      }
    }
  }
  for (int i = 0; i <= k; ++i) {
    for (int j = 0; j <= n; ++j) {
      ans = max(ans, f[n][i][j]);
    }
  }
  printf("%d", ans);
  return 0;
}
