#include <bits/stdc++.h>
void merge(long long int[], long long int, long long int, long long int);
void part(long long int[], long long int, long long int);
int main() {
  long long int i, n, k, ans;
  scanf("%lld %lld", &n, &k);
  char word[n];
  scanf("%s", word);
  long long int arr[26] = {0};
  for (i = 0; i < n; i++) {
    arr[word[i] - 'A'] = arr[word[i] - 'A'] + 1;
  }
  part(arr, 0, 25);
  if (arr[25] == k)
    ans = arr[25] * arr[25];
  else if (arr[25] > k)
    ans = k * k;
  else if (arr[25] < k) {
    k = k - arr[25];
    ans = arr[25] * arr[25];
    for (i = 24; i >= 0; i--) {
      if (arr[i] <= k && k > 0) {
        ans = ans + (arr[i] * arr[i]);
        k = k - arr[i];
        if (k == 0) break;
      } else if (arr[i] >= k) {
        ans = ans + (k * k);
        break;
      }
    }
  }
  printf("%lld", ans);
  return 0;
}
void part(long long int arr[], long long int min, long long int max) {
  long long int mid;
  if (min < max) {
    mid = (min + max) / 2;
    part(arr, min, mid);
    part(arr, mid + 1, max);
    merge(arr, min, mid, max);
  }
}
void merge(long long int arr[], long long int min, long long int mid,
           long long int max) {
  long long int tmp[30];
  long long int i, j, k, m;
  j = min;
  m = mid + 1;
  for (i = min; j <= mid && m <= max; i++) {
    if (arr[j] <= arr[m]) {
      tmp[i] = arr[j];
      j++;
    } else {
      tmp[i] = arr[m];
      m++;
    }
  }
  if (j > mid) {
    for (k = m; k <= max; k++) {
      tmp[i] = arr[k];
      i++;
    }
  } else {
    for (k = j; k <= mid; k++) {
      tmp[i] = arr[k];
      i++;
    }
  }
  for (k = min; k <= max; k++) arr[k] = tmp[k];
}
