#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 + 5;
int num[MAXN];
vector<long long> temp;
int main() {
  int n, i, j, k;
  scanf("%d%d%", &n, &k);
  for (i = 0; i < n; i++) {
    char ch = getchar();
    num[ch - 'A']++;
  }
  for (i = 0; i < 30; i++)
    if (num[i]) temp.push_back(num[i]);
  long long ans = 0;
  sort(temp.begin(), temp.end());
  for (i = temp.size() - 1; i >= 0; i--) {
    if (k >= temp[i]) {
      ans += (long long)temp[i] * temp[i];
      k -= temp[i];
    } else {
      ans += (long long)k * k;
      break;
    }
  }
  printf("%I64d\n", ans);
  return 0;
}
