#include <bits/stdc++.h>
using namespace std;
vector<long long> alpha(26);
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  long long n, k, lim, i;
  long long ans = 0;
  cin >> n >> k;
  string str;
  cin >> str;
  lim = str.size();
  for (i = 0; i < lim; i++) alpha[str[i] - 'A']++;
  sort(alpha.begin(), alpha.end());
  for (i = 25; i >= 0; i--) {
    if (k >= alpha[i])
      ans += (alpha[i] * alpha[i]), k -= alpha[i];
    else if (k > 0) {
      ans += (k * k);
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
