#include <bits/stdc++.h>
const int MAX = 105000;
using namespace std;
int main() {
  int n, k;
  long long sum = 0;
  char A[MAX];
  vector<int> L(30);
  for (int i = 0; i < 30; i++) L[i] = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    L[(int)A[i] - (int)'A']++;
  }
  sort(&L[0], &L[26]);
  int j = 25;
  while ((k > 0) && (j >= 0)) {
    if (k >= L[j]) {
      k -= L[j];
      sum += (long long)L[j] * L[j];
    } else {
      sum += (long long)k * k;
      k = 0;
    }
    j--;
  }
  cout << sum << endl;
  return 0;
}
