#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, i, j;
  cin >> n >> k;
  int arr[26];
  for (i = 0; i < 26; i++) {
    arr[i] = 0;
  }
  string str;
  cin >> str;
  int len = str.size();
  for (i = 0; i < len; i++) {
    arr[str[i] - 65]++;
  }
  sort(arr, arr + 26);
  long long int ans = 0;
  for (i = 25; i >= 0; i--) {
    if (k == arr[i]) {
      ans = ans + (1LL * arr[i] * arr[i]);
      break;
    } else if (k < arr[i]) {
      ans = ans + (1LL * k * k);
      break;
    } else {
      ans = ans + (1LL * arr[i] * arr[i]);
      k = k - arr[i];
    }
  }
  cout << ans << endl;
  return 0;
}
