#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  string str;
  cin >> n >> k >> str;
  map<char, long long int> M;
  vector<long long int> v;
  for (long long int i = 0; i < n; i++) {
    M[str[i]]++;
  }
  for (auto x : M) {
    v.push_back(x.second);
  }
  sort(v.rbegin(), v.rend());
  long long sum = 0;
  while (k > 0)
    for (auto x : v) {
      if (k >= x) {
        sum += x * x;
        k -= x;
      } else {
        sum += k * k;
        k = 0;
      }
    }
  cout << sum;
  return 0;
}
