#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k;
  cin >> n >> k;
  char A[n];
  long long int count[30] = {0};
  for (long long int i = 0; i < n; i++) {
    cin >> A[i];
  }
  for (long long int i = 0; i < n; i++) count[A[i] - 65]++;
  std::sort(count, count + 30);
  long long int p = 0, q = 0, val = 0, i = 29;
  while (q < k) {
    if (count[i] <= k - q && q < k) {
      p = count[i];
      count[i] = 0;
      i--;
      val += p * p;
      q += p;
    } else if (q < k && count[i] > 0) {
      p = k - q;
      val += p * p;
      q += p;
      i--;
    }
  }
  cout << val;
}
