#include <bits/stdc++.h>
using namespace std;
long long c[30];
int main() {
  long long n, k, l = 25, total = 0;
  cin >> n >> k;
  string s;
  cin >> s;
  for (int i = 0; i < 30; i++) c[i] = 0;
  for (long i = 0; i < n; i++) c[s[i] - 65]++;
  sort(c, c + 26);
  while (k > 0) {
    if (k >= c[l]) {
      total += c[l] * c[l];
      k -= c[l];
      l--;
    } else {
      total += k * k;
      k = 0;
    }
  }
  cout << total << endl;
  return 0;
}
