#include <bits/stdc++.h>
using namespace std;
const int N = 205, M = 2e4 + 5, inf = 0x3f3f3f3f, mod = 1e9 + 7;
int dp[N][N][N], n, k;
int main() {
  string s, t;
  cin >> n >> k >> s >> t;
  int e01 = t[0] == t[1];
  memset(dp, -69, sizeof dp);
  dp[0][0][0] = 0;
  for (int i = 0; i < n; i++) {
    int e0 = s[i] == t[0], e1 = s[i] == t[1];
    for (int j = 0; j <= k; j++) {
      for (int l = 0; l <= i; l++) {
        dp[i + 1][j][l + e0] = max(dp[i + 1][j][l + e0], dp[i][j][l] + e1 * l);
        dp[i + 1][j + 1][l + 1] =
            max(dp[i + 1][j + 1][l + 1], dp[i][j][l] + e01 * l);
        dp[i + 1][j + 1][l + e01] =
            max(dp[i + 1][j + 1][l + e01], dp[i][j][l] + l);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= k; i++)
    for (int j = 0; j <= n; j++) ans = max(ans, dp[n][i][j]);
  cout << ans << endl;
  return 0;
}
