#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
static void amax(T &x, U y) {
  if (x < y) x = y;
}
template <typename T, typename U>
static void amin(T &x, U y) {
  if (x > y) x = y;
}
int main() {
  int n, k, b;
  scanf("%d%d", &n, &k);
  vector<int> a(200), v;
  vector<char> c;
  string s;
  cin >> s;
  for (int i = 0; i < (s.size()); i++) {
    if (!a[s[i]]) c.push_back(s[i]);
    ++a[s[i]];
  }
  for (int i = 0; i < (c.size()); i++) v.push_back(a[c[i]]);
  sort(v.rbegin(), v.rend());
  b = 0;
  long long ans, t;
  ans = 0;
  while (k > 0) {
    t = 1e7;
    amin(t, k);
    amin(t, v[b]);
    k -= v[b];
    ++b;
    ans += t * t;
  }
  printf("%lld\n", ans);
  return 0;
}
