#include <bits/stdc++.h>
using namespace std;
typedef struct {
  long long loc;
  long long num;
} amar;
bool operator<(amar x, amar y) {
  if (x.num >= y.num)
    return false;
  else
    return true;
}
int main() {
  long long n, k, c[40];
  char s[100005];
  memset(c, 0, sizeof c);
  cin >> n >> k >> s;
  for (long long i = 0; i < n; i++) {
    c[s[i] - 'A']++;
  }
  priority_queue<amar> a;
  amar tmp;
  for (long long i = 0; i < 40; i++) {
    tmp.loc = i;
    tmp.num = c[i];
    a.push(tmp);
  }
  long long ans = 0;
  while (k > 0 && !a.empty()) {
    tmp = a.top();
    if (k >= tmp.num) {
      ans += (tmp.num * tmp.num);
      k -= tmp.num;
    } else if (k < tmp.num) {
      ans += k * k;
      k = 0;
    }
    a.pop();
  }
  cout << ans << endl;
  return 0;
}
