#include <bits/stdc++.h>
using namespace std;
const int inf = int(1e9 + 7);
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int len;
  long long pick;
  cin >> len >> pick;
  string str;
  cin >> str;
  map<char, int> counter;
  for (int i = 0; i < len; i++) counter[str[i]]++;
  vector<long long> vec;
  for (map<char, int>::iterator it = counter.begin(); it != counter.end();
       ++it) {
    int aux = it->second;
    vec.push_back(aux);
  }
  sort((vec).rbegin(), (vec).rend());
  long long ans = 0LL;
  int i = 0;
  while (pick > 0) {
    long long need = vec[i];
    if (pick >= need) {
      pick -= need;
      ans += need * need;
    } else if (pick < need) {
      ans += pick * pick;
      pick = 0;
    }
    i++;
  }
  cout << ans << "\n";
  return 0;
}
