#include <bits/stdc++.h>
using namespace std;
long long num[27];
int main() {
  long long n, k;
  char arr[100005];
  while (scanf("%lld%lld", &n, &k) != EOF) {
    scanf("%s", arr);
    memset(num, 0, sizeof(num));
    int len = strlen(arr);
    int ok = 0;
    long long ans = 0;
    for (int i = 0; i < len && !ok; i++) {
      num[arr[i] - 'A']++;
      if (num[arr[i] - 'A'] >= k) {
        ok = 1;
        ans = k * k;
      }
    }
    if (!ok) {
      sort(num, num + 26);
      for (int i = 25; i >= 0 && k; i--) {
        if (num[i] <= k) {
          ans += num[i] * num[i];
          k -= num[i];
        } else {
          ans += k * k;
          break;
        }
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
