#include <bits/stdc++.h>
using namespace std;
int gcd(const long long &a, const long long &b) {
  return b == 0 ? a : gcd(b, a % b);
}
long long int64pow(long long a, long long b) {
  if (b == 0) return 1;
  long long t = int64pow(a, b / 2);
  if (b % 2) return t * t * a;
  return t * t;
}
const int inf = 1 << 30;
const double eps = 1e-8;
const double pi = acos(-1.0);
const int MAX_N = 500005;
long long n, k, ans;
string s;
map<char, int> m;
void solve() {
  m.clear();
  ans = 0;
  cin >> s;
  for (int(i) = (int)(0); (i) < (int)((int)((s).size())); ++(i)) {
    ++m[s[i]];
  }
  while (k > 0) {
    long long MAX = -inf;
    long long pos = -1;
    for (int(i) = (int)(0); (i) < (int)((int)((m).size())); ++(i)) {
      if (MAX < m[i]) {
        MAX = m[i];
        pos = i;
      }
    }
    if (k <= MAX) {
      ans += k * k;
      k = 0;
    }
    if (k > MAX) {
      ans += MAX * MAX;
      k -= MAX;
      m[pos] = 0;
    }
  }
  cout << ans << endl;
}
int main() {
  while (cin >> n >> k) {
    solve();
  }
  return 0;
}
