#include <bits/stdc++.h>
using namespace std;
char letter[100005];
int64_t n, k, m[27];
int64_t p;
int main() {
  cin >> n >> k;
  scanf("%s", letter);
  memset(m, 0, sizeof(m));
  for (int i = 0; i < n; i++) m[letter[i] - 'A']++;
  sort(m, m + 26);
  bool flag = true;
  p = 0;
  while (flag) {
    for (int i = 25; i >= 0; i--) {
      k -= m[i];
      if (k <= 0) {
        p += ((k + m[i]) * (k + m[i]));
        flag = 0;
        break;
      } else {
        p += (m[i] * m[i]);
      }
    }
  }
  cout << p << endl;
  return 0;
}
