#include <bits/stdc++.h>
using namespace std;
int main() {
  int countChar[26];
  for (int i = 0; i < 26; i++) countChar[i] = 0;
  int n, k;
  char a;
  cin >> n;
  cin >> k;
  for (int i = 0; i < n; i++) {
    cin >> a;
    ++countChar[a - 'A'];
  }
  long long numCoins = 0;
  while (k > 0) {
    int max, pos;
    pos = 0;
    max = countChar[0];
    for (int i = 1; i < 26; i++)
      if (countChar[i] > max) {
        max = countChar[i];
        pos = i;
      }
    if (max > k) {
      numCoins += (static_cast<long long>(k) * k);
      k = 0;
      countChar[pos] -= k;
    } else {
      numCoins += (static_cast<long long>(max) * max);
      k -= max;
      countChar[pos] = 0;
    }
  }
  cout << numCoins;
  return 0;
}
