#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const double PI = acos(-1.0);
const double epsilon = PI / 180.0;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
const int N = 2e2 + 10, M = 1e6 + 10;
int n, m;
char s[N], t[10];
int dp[N][N][N];
int main() {
  cin >> n >> m;
  scanf(" %s", s + 1);
  scanf(" %s", t + 1);
  memset(dp, -0x3f3f3f3f, sizeof dp);
  dp[0][0][0] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= min(m, i); j++) {
      for (int k = 0; k <= i; k++) {
        if (t[1] == t[2]) {
          if (s[i] == t[1]) {
            if (k >= 1)
              dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j][k - 1] + k - 1);
          } else {
            dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j][k]);
            if (j >= 1 && k >= 1)
              dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j - 1][k - 1] + k - 1);
          }
        } else {
          if (s[i] == t[1]) {
            if (k >= 1) dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j][k - 1]);
            if (j >= 1) dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j - 1][k] + k);
          } else if (s[i] == t[2]) {
            if (j >= 1 && k >= 1)
              dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j - 1][k - 1]);
            dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j][k] + k);
          } else {
            dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j][k]);
            if (j >= 1 && k >= 1)
              dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j - 1][k - 1]);
            if (j >= 1) dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j - 1][k] + k);
          }
        }
      }
    }
  }
  int ans = 0;
  for (int j = 0; j <= m; j++) {
    for (int k = 0; k <= n; k++) {
      ans = max(ans, dp[n][j][k]);
    }
  }
  cout << ans << "\n";
  return 0;
}
