#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
vector<pair<long long int, long long int> > ctr;
int main() {
  long long int n, k, i;
  char ch;
  long long int a[26] = {0};
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> ch;
    a[ch - 'A']++;
  }
  for (i = 0; i < 26; i++) {
    ctr.push_back(make_pair(a[i], i));
  }
  sort(ctr.begin(), ctr.end());
  reverse(ctr.begin(), ctr.end());
  long long int sum = 0;
  i = 0;
  while (k > 0 && i < 26) {
    if (ctr[i].first <= k) {
      sum += ctr[i].first * ctr[i].first;
      k -= ctr[i].first;
    } else {
      sum += k * k;
      k = 0;
    }
    i++;
  }
  cout << sum << endl;
  return 0;
}
