#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
char record[maxn];
int main() {
  long long cot[28];
  for (int i = 0; i < 26; i++) {
    cot[i] = 0;
  }
  long long n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> record[i];
    cot[record[i] - 65]++;
  }
  sort(cot, cot + 26);
  int index = 25;
  long long sum = 0;
  while (k) {
    if (k > cot[index]) {
      k -= cot[index];
      sum += cot[index] * cot[index];
      index--;
    } else {
      sum += k * k;
      k = 0;
    }
  }
  cout << sum << endl;
  return 0;
}
