#include <bits/stdc++.h>
using namespace std;
long long int a[26];
int main() {
  long long int i, j, k, n, m = 0, c = 0, p, l;
  char ch;
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> ch;
    a[ch - 65] = a[ch - 65] + 1;
  }
  sort(a, a + 26);
  i = 25;
  while (k > 0) {
    if (a[i] >= k) {
      c = c + (k * k);
      k = 0;
    } else {
      k = k - a[i];
      c = c + (a[i] * a[i]);
    }
    i = i - 1;
  }
  cout << c << endl;
  return 0;
}
