#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  long long mp[26];
  memset(mp, 0, sizeof(mp));
  string s;
  cin >> s;
  for (int i = 0; i < s.length(); i++) mp[s[i] - 'A']++;
  sort(mp, mp + 26);
  reverse(mp, mp + 26);
  int ii = 0;
  long long ans = 0;
  while (k > 0) {
    if (mp[ii] <= k) {
      ans += (mp[ii] * mp[ii]);
      k -= mp[ii];
    } else {
      ans += k * k;
      k = 0;
    }
    ii++;
  }
  cout << ans << endl;
}
