#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long INF = 1e18;
const double EPS = 1e-9;
const int MAXN = 222;
string s, t;
int n, k;
vector<int> non, a, b;
int curS[MAXN], origS[MAXN];
int curAns, origAns;
int bit0[MAXN], bit1[MAXN];
void updateBIT(int* BIT, int n, int i, int val) {
  for (i++; i <= n; i += i & -i) {
    BIT[i] += val;
  }
}
int queryBIT(int* BIT, int n, int i) {
  int ret = 0;
  for (i++; i > 0; i -= i & -i) {
    ret += BIT[i];
  }
  return ret;
}
int queryBIT(int* BIT, int n, int i, int j) {
  return queryBIT(BIT, n, j) - (i == 0 ? 0 : queryBIT(BIT, n, i - 1));
}
void updateS(int i, int x) {
  int delta0 = i + 1 < n ? queryBIT(bit1, n, i + 1, n - 1) : 0;
  int delta1 = i > 0 ? queryBIT(bit0, n, 0, i - 1) : 0;
  if (curS[i] == 0) {
    curAns -= delta0;
    updateBIT(bit0, n, i, -1);
  } else if (curS[i] == 1) {
    curAns -= delta1;
    updateBIT(bit1, n, i, -1);
  }
  if (x == 0) {
    curAns += delta0;
    updateBIT(bit0, n, i, 1);
  } else if (x == 1) {
    curAns += delta1;
    updateBIT(bit1, n, i, 1);
  }
  curS[i] = x;
}
void restoreS() {
  curAns = origAns;
  fill(bit0, bit0 + n + 1, 0);
  fill(bit1, bit1 + n + 1, 0);
  for (int i = 0; i < n; i++) {
    curS[i] = origS[i];
    if (curS[i] == 0) {
      updateBIT(bit0, n, i, 1);
    } else if (curS[i] == 1) {
      updateBIT(bit1, n, i, 1);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k >> s >> t;
  if (t[0] == t[1]) {
    int ct = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == t[0]) ct++;
    }
    int new_ct = min(ct + k, n);
    cout << new_ct * (new_ct - 1) / 2 << '\n';
    return 0;
  }
  int cur0 = 0;
  int diff_perfect = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == t[0]) {
      a.push_back(i);
      origS[i] = 0;
      cur0++;
    } else if (s[i] == t[1]) {
      b.push_back(i);
      origS[i] = 1;
      origAns += cur0;
    } else {
      non.push_back(i);
      origS[i] = 2;
    }
    if (i < n / 2) {
      if (origS[i] != 0) diff_perfect++;
    }
    if (i >= (n + 1) / 2) {
      if (origS[i] != 1) diff_perfect++;
    }
  }
  k = min(k, diff_perfect);
  int ans = 0;
  for (int pre_b = 0; pre_b <= k; pre_b++) {
    if (pre_b > int((b).size())) break;
    for (int suf_a = 0; pre_b + suf_a <= k; suf_a++) {
      if (suf_a > int((a).size())) break;
      int remain = k - (pre_b + suf_a);
      if (remain > int((non).size())) continue;
      restoreS();
      for (int i = 0; i < pre_b; i++) {
        updateS(b[i], 0);
      }
      for (int i = 0; i < suf_a; i++) {
        updateS(a[int((a).size()) - 1 - i], 1);
      }
      for (int i = 0; i < remain; i++) {
        updateS(non[int((non).size()) - 1 - i], 1);
      }
      for (int pre_non = 0; pre_non <= remain; pre_non++) {
        int suf_non = remain - pre_non;
        ans = max(curAns, ans);
        if (pre_non != remain) {
          if (pre_non == int((non).size()) - suf_non) {
            updateS(non[pre_non], 0);
          } else {
            updateS(non[pre_non], 0);
            updateS(non[int((non).size()) - suf_non], 2);
          }
        }
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
