#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
const int INF = 1e9;
int n;
long long cnt[30], k;
int main() {
  char s[maxn];
  while (~scanf("%d%I64d", &n, &k)) {
    scanf("%s", s);
    memset(cnt, 0, sizeof(cnt));
    for (int i = 0; s[i]; i++) cnt[s[i] - 'A']++;
    sort(cnt, cnt + 26);
    long long ans = 0;
    for (int i = 25; i >= 0; i--) {
      if (k >= cnt[i]) {
        ans += cnt[i] * cnt[i];
        k -= cnt[i];
      } else {
        ans += k * k;
        k = 0;
      }
      if (k == 0) break;
    }
    cout << ans << endl;
  }
  return 0;
}
