#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(int argc, const char* argv[]) {
  ios_base::sync_with_stdio();
  cin.tie(0);
  cout.tie(0);
  ll n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  map<char, ll> m;
  for (ll i = 0; i < s.length(); i++) {
    m[s[i]]++;
  }
  vector<ll> v(m.size());
  for (auto i : m) {
    v.push_back(i.second);
  }
  sort(v.begin(), v.end());
  ll ans = 0;
  ll taken = 0;
  ll i = v.size() - 1;
  while (k > 0) {
    if (k < v[i]) {
      ans += k * k;
      k = 0;
    } else {
      ans += v[i] * v[i];
      k -= v[i];
    }
    i--;
  }
  cout << ans;
  return 0;
}
