#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long A[30];
char c;
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> c;
    A[c - 'A']++;
  }
  sort(A, A + 26);
  long long sum = 0;
  int i = 25;
  while (k > 0) {
    if (A[i] <= k) {
      sum = sum + A[i] * A[i];
      k = k - A[i];
    } else {
      sum = sum + k * k;
      k = 0;
    }
    --i;
  }
  cout << sum << endl;
  return 0;
}
