#include <bits/stdc++.h>
using namespace std;
int main() {
  long long unsigned n, k, resp = 0;
  cin >> n >> k;
  string s;
  cin >> s;
  sort(s.begin(), s.end());
  long long unsigned arr[26] = {};
  int index = 0;
  arr[0] = 1;
  long long unsigned maxi = 0, atual = 1;
  for (long long unsigned i = 1; i < n; i++) {
    if (s[i - 1] == s[i]) {
      arr[index]++;
    } else {
      index++;
      arr[index]++;
    }
  }
  sort(arr, arr + 25);
  for (int j = 26 - 1; (j >= 0) && (k > 0); j--) {
    if (arr[j] <= k) {
      resp += arr[j] * arr[j];
      k = k - arr[j];
    } else {
      resp += k * k;
      k = 0;
      break;
    }
  }
  cout << resp;
  return 0;
}
