#include <bits/stdc++.h>
using namespace std;
char s[100005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, k;
  cin >> n >> k;
  map<char, long long> fr;
  for (long long i = 0; i < n; i++) {
    cin >> s[i];
    fr[s[i]]++;
  }
  vector<pair<long long, char> > f;
  for (map<char, long long>::iterator fit = fr.begin(); fit != fr.end();
       ++fit) {
    f.push_back(make_pair(fit->second, fit->first));
  }
  sort(f.begin(), f.end(), greater<pair<long long, char> >());
  long long ans = 0;
  for (int i = 0; i < f.size(); i++) {
    if (k - f[i].first >= 0) {
      k -= f[i].first;
      ans += f[i].first * f[i].first;
    } else {
      ans += k * k;
      break;
    }
  }
  cout << ans << "\n";
  return 0;
}
