#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, n, k;
  scanf("%lld", &n);
  scanf("%lld", &k);
  string s;
  cin >> s;
  map<char, long long int> cnt;
  for (i = 0; i < s.size(); i++) {
    cnt[s[i]]++;
  }
  string ref = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  long long int ma = INT_MIN;
  pair<long long int, char> Y[26];
  for (i = 0; i < ref.size(); i++) {
    Y[i].first = cnt[ref[i]];
    Y[i].second = ref[i];
  }
  sort(Y, Y + 26);
  long long int j = 25;
  long long int ans = 0;
  while (k > 0) {
    if (Y[j].first > k) {
      ans += k * k;
      k -= k;
      Y[j].first = 0;
      j--;
    } else {
      k -= Y[j].first;
      ans += Y[j].first * Y[j].first;
      Y[j].first = 0;
      j--;
    }
  }
  cout << ans << endl;
  return 0;
}
