#include <bits/stdc++.h>
using namespace std;
const long double pi = 4 * atan((long double)1);
const long long mod = 1e9 + 7;
const long long inf = 922337203685477;
const long long nax = 0;
long long n, k;
long long memo[205][205][205];
string s, t;
long long dp(long long idx, long long x, long long cur) {
  if (idx == s.size()) {
    return 0;
  }
  if (memo[idx][x][cur] != -1) {
    return memo[idx][x][cur];
  }
  long long ret = dp(idx + 1, x, cur);
  if (s[idx] == t[0] && s[idx] == t[1]) {
    ret = max(ret, dp(idx + 1, x + 1, cur) + x);
  } else if (s[idx] == t[0]) {
    if (cur > 0) {
      ret = max(ret, dp(idx + 1, x, cur - 1) + x);
    }
    ret = max(ret, dp(idx + 1, x + 1, cur));
  } else if (s[idx] == t[1]) {
    if (cur > 0) {
      ret = max(ret, dp(idx + 1, x + 1, cur - 1));
    }
    ret = max(ret, dp(idx + 1, x, cur) + x);
  } else {
    if (cur > 0) {
      if (t[0] == t[1]) {
        ret = max(ret, dp(idx + 1, x + 1, cur - 1) + x);
      } else {
        ret = max(ret, dp(idx + 1, x, cur - 1) + x);
        ret = max(ret, dp(idx + 1, x + 1, cur - 1));
      }
    }
  }
  return memo[idx][x][cur] = ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  memset(memo, -1, sizeof(memo));
  cin >> n >> k;
  cin >> s >> t;
  cout << dp(0, 0, k) << '\n';
}
