#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 2e2 + 5;
int n, k;
char s[maxn], t[4];
ll dp[maxn][maxn][maxn], ans;
int main() {
  scanf("%d%d", &n, &k);
  scanf("%s", s + 1);
  scanf("%s", t);
  if (t[0] == t[1]) {
    ll sum = 0;
    for (int i = 1; i <= n; i++) {
      if (s[i] == t[0]) sum++;
      if (s[i] != t[0] and k > 0) sum++, k--;
    }
    printf("%lld", sum * (sum - 1) / 2ll);
    return 0;
  }
  memset(dp, -1, sizeof(dp));
  dp[0][0][0] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= min(i, k); j++) {
      for (int l = 0; l <= i; l++) {
        if (s[i] == t[0]) {
          if (l > 0) dp[i][j][l] = max(dp[i][j][l], dp[i - 1][j][l - 1]);
          if (j > 0 and dp[i - 1][j - 1][l] != -1)
            dp[i][j][l] = max(dp[i][j][l], dp[i - 1][j - 1][l] + l);
        } else if (s[i] == t[1]) {
          if (j > 0 and l > 0)
            dp[i][j][l] = max(dp[i][j][l], dp[i - 1][j - 1][l - 1]);
          if (dp[i - 1][j][l] != -1)
            dp[i][j][l] = max(dp[i][j][l], dp[i - 1][j][l] + l);
        } else {
          if (j > 0 and l > 0)
            dp[i][j][l] = max(dp[i][j][l], dp[i - 1][j - 1][l - 1]);
          if (j > 0 and dp[i - 1][j - 1][l] != -1)
            dp[i][j][l] = max(dp[i][j][l], dp[i - 1][j - 1][l] + l);
          dp[i][j][l] = max(dp[i][j][l], dp[i - 1][j][l]);
        }
      }
    }
  }
  for (int i = 0; i <= k; i++)
    for (int j = 0; j <= n; j++) ans = max(ans, dp[n][i][j]);
  printf("%lld", ans);
}
