#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  long long n, k, ans = 0;
  cin >> n >> k;
  string s;
  cin >> s;
  map<char, long long> mp;
  vector<pair<long long, char> > v;
  for (int i = 0; i < n; i++) {
    mp[s[i]]++;
  }
  for (auto x : mp) {
    v.push_back(make_pair(x.second, x.first));
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) {
    if (k > 0 && v[i].first > 0) {
      if (k >= v[i].first) {
        ans += v[i].first * v[i].first;
        k -= v[i].first;
      } else if (k < v[i].first) {
        ans += k * k;
        k = 0;
      }
    }
  }
  cout << ans;
}
