#include <bits/stdc++.h>
using namespace std;
string s, t;
long long int n;
long long int dp[201][201][201];
long long int go(long long int pos, long long int cnt, long long int k) {
  if (pos == n) {
    return 0;
  }
  if (dp[pos][cnt][k] != -1) {
    return dp[pos][cnt][k];
  }
  long long int flg = (s[pos] == t[0]);
  long long int ans = go(pos + 1, cnt + flg, k);
  if (s[pos] == t[1]) {
    ans += cnt;
  }
  if (k > 0) {
    if (t[0] == t[1]) {
      ans = max(ans, cnt + go(pos + 1, cnt + 1, k - 1));
    } else {
      ans = max(ans, go(pos + 1, cnt + 1, k - 1));
      ans = max(ans, cnt + go(pos + 1, cnt, k - 1));
    }
  }
  return dp[pos][cnt][k] = ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int k;
  cin >> n >> k;
  cin >> s >> t;
  memset(dp, -1, sizeof(dp));
  cout << go(0, 0, k) << "\n";
}
