#include <bits/stdc++.h>
using namespace std;
int n, k;
string s, t;
vector<vector<vector<int>>> dp(201,
                               vector<vector<int>>(201, vector<int>(201, -1)));
int go(int i, int j, int a) {
  if (i == n) return 0;
  if (dp[i][j][a] != -1) return dp[i][j][a];
  int ans = 0;
  if (s[i] == t[0]) {
    ans = max(ans, go(i + 1, j, a + 1));
    if (j > 0) ans = max(ans, a + go(i + 1, j - 1, a));
  } else if (s[i] == t[1]) {
    ans = max(ans, a + go(i + 1, j, a));
    if (j > 0) ans = max(ans, go(i + 1, j - 1, a + 1));
  } else {
    ans = max(ans, go(i + 1, j, a));
    if (j > 0) {
      ans = max(ans, go(i + 1, j - 1, a + 1));
      ans = max(ans, a + go(i + 1, j - 1, a));
    }
  }
  return dp[i][j][a] = ans;
}
int main() {
  cin >> n >> k >> s >> t;
  if (t[0] == t[1]) {
    int x = 0;
    for (const char c : s) {
      if (c == t[0]) ++x;
    }
    x = min(n, x + k);
    cout << (x * (x - 1)) / 2;
    return 0;
  }
  cout << go(0, k, 0);
}
