#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  vector<pair<long long, char> > v;
  map<char, long long> mp;
  for (long long i = 0; i < s.size(); ++i) {
    if (mp[s[i]] == 0) v.push_back({0, s[i]});
    ++mp[s[i]];
  }
  for (long long i = 0; i < v.size(); ++i) v[i].first = mp[v[i].second];
  sort(v.begin(), v.end());
  long long ans = 0, cnt = 0;
  for (long long i = v.size() - 1; i >= 0; --i) {
    if (ans >= k) break;
    if (ans + v[i].first <= k) {
      ans += v[i].first;
      cnt = cnt + v[i].first * v[i].first;
    } else if (ans + v[i].first > k) {
      cnt = cnt + (k - ans) * (k - ans);
      break;
    }
  }
  cout << cnt << '\n';
  return 0;
}
