#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k;
  cin >> n >> k;
  char a[n];
  long long int b[130] = {0}, ans = 0;
  cin >> a;
  for (int i = 0; i < n; i++) {
    b[a[i]]++;
  }
  sort(b, b + 130);
  for (int i = 129; i >= 65; i--) {
    if (b[i] <= k) {
      ans = ans + (b[i] * b[i]);
      k = k - b[i];
    } else {
      ans = ans + (k * k);
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
