#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, j, k;
  long long int n;
  string s;
  map<char, long long int> cs;
  cin >> n >> k;
  cin >> s;
  for (i = 0; i < s.length(); i++) {
    cs[s[i]]++;
  }
  vector<long long int> v;
  map<char, long long int>::iterator p = cs.begin();
  while (p != cs.end()) {
    v.push_back(p->second);
    p++;
  }
  long long int count = 0;
  sort(v.begin(), v.end(), greater<long long int>());
  i = 0;
  while (k > 0 && i < v.size()) {
    if (v[i] > k) {
      count += (k * k);
      break;
    } else {
      k -= v[i];
      count += (v[i] * v[i]);
    }
    i++;
  }
  cout << count;
  return 0;
}
