#include <bits/stdc++.h>
using namespace std;
void swap(long long int *xp, long long int *yp) {
  long long int t = *xp;
  *xp = *yp;
  *yp = t;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  long long int arr[26] = {0}, brr[26] = {0};
  for (long long int i = 0; i < s.length(); i++) arr[s[i] - 'A']++;
  while (k > 0) {
    long long int max = 0;
    for (long long int i = 0; i < 26; i++)
      if (arr[i] > arr[max]) max = i;
    long long int key = (long long int)fmin(k, arr[max]);
    brr[max] += key;
    arr[max] = 0;
    k -= key;
  }
  long long int c = 0;
  for (long long int i = 0; i < 26; i++) {
    if (brr[i] != 0) c += brr[i] * brr[i];
  }
  cout << c << endl;
  return 0;
}
