#include <bits/stdc++.h>
using namespace std;
string word;
long long int cuantities[200];
int main() {
  long long int n, k;
  cin >> n >> k;
  getline(cin, word);
  getline(cin, word);
  for (int i = 0; i < (word.size()); i++) {
    cuantities[(int)(word[i] - 'A')]++;
  }
  long long int maxim = 0, sum = 0, max_id;
  while (k != 0) {
    maxim = 0;
    for (int i = 0; i < (200); i++) {
      if (cuantities[i] > maxim) {
        maxim = cuantities[i];
        max_id = i;
      }
    }
    if (maxim <= k) {
      k -= maxim;
      sum += maxim * maxim;
      cuantities[max_id] = 0;
    } else {
      sum += k * k;
      k = 0;
    }
  }
  cout << sum << endl;
  return 0;
}
