#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long int n, k, i, p;
  scanf("%ld%ld", &n, &k);
  char a[n + 1];
  getchar();
  scanf("%s", a);
  long int c[26] = {0};
  for (i = 0; i < n; i++) {
    c[a[i] - 65]++;
  }
  unsigned long long int ans = 0;
  sort(c, c + 26);
  for (i = 25; i >= 0 && k > 0; i--) {
    if (c[i] > k) {
      ans = ans + (unsigned long long int)k * k;
      break;
    } else {
      ans = ans + (unsigned long long int)c[i] * c[i];
      k = k - c[i];
    }
  }
  printf("%I64d\n", ans);
  return 0;
}
