#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  string s;
  cin >> n >> k >> s;
  if (k == 1) {
    cout << 1;
    return 0;
  }
  vector<int> a(26);
  for (char c : s) {
    ++a[c - 'A'];
  }
  sort(a.rbegin(), a.rend());
  int p = 0;
  long long ans = 0;
  long long temp = 0;
  while (p <= 26 && k > 0) {
    temp = min(k, a[p++]);
    ans += temp * temp;
    k -= temp;
  }
  cout << ans;
  return 0;
}
