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