#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  char ch[n];
  for (long long i = 0; i < n; i++) cin >> ch[i];
  long long frq[27];
  for (long long i = 0; i < 27; i++) frq[i] = 0;
  for (long long i = 0; i < n; i++) {
    frq[ch[i] - 64]++;
  }
  sort(frq, frq + 27);
  long long ans = 0;
  long long ind = 26;
  while (ind > 0 && k > 0) {
    if (k >= frq[ind]) {
      ans += frq[ind] * frq[ind];
      k -= frq[ind];
      ind--;
    } else {
      ans += k * k;
      break;
    }
  }
  cout << ans;
}
