#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  ll f, k;
  cin >> f >> k;
  ll fr[26] = {0};
  vector<ll> ar;
  string s;
  cin >> s;
  for (ll i = 0; i < s.size(); i++) fr[s[i] - 'A']++;
  for (ll i = 0; i < 26; i++)
    if (fr[i] != 0) ar.push_back(fr[i]);
  sort(ar.begin(), ar.end());
  ll n = ar.size();
  ll sum = 0;
  for (ll i = n - 1; i >= 0; i--) {
    if (ar[i] >= k) {
      cout << k * k + sum;
      return 0;
    }
    if (ar[i] < k) {
      sum += ar[i] * ar[i];
      k -= ar[i];
    }
  }
  return 0;
}
