#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, k;
  cin >> n >> k;
  string s, t;
  cin >> s >> t;
  int dp[n + 1][k + 1][n + 1];
  memset(dp, -1, sizeof(dp));
  dp[0][0][0] = 0;
  for (int curPos = 0; curPos < n; curPos++) {
    for (int changes = 0; changes <= min(k, curPos + 1); changes++) {
      for (int cnt0 = 0; cnt0 <= curPos + 1; cnt0++) {
        if (dp[curPos][changes][cnt0] == -1) continue;
        dp[curPos + 1][changes][cnt0 + (s[curPos] == t[0])] = max(
            dp[curPos + 1][changes][cnt0 + (s[curPos] == t[0])],
            dp[curPos][changes][cnt0] + ((s[curPos] == t[1]) ? (cnt0) : (0)));
        if (changes == k) continue;
        dp[curPos + 1][changes + 1][cnt0 + 1] =
            max(dp[curPos + 1][changes + 1][cnt0 + 1],
                dp[curPos][changes][cnt0] + ((t[0] == t[1]) ? (cnt0) : (0)));
        dp[curPos + 1][changes + 1][cnt0 + (t[0] == t[1])] =
            max(dp[curPos + 1][changes + 1][cnt0 + (t[0] == t[1])],
                dp[curPos][changes][cnt0] + cnt0);
      }
    }
  }
  int ans = 0;
  for (int j = 0; j <= k; j++)
    for (int kk = 0; kk <= n; kk++) ans = max(ans, dp[n][j][kk]);
  cout << ans << endl;
}
