#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long int n) {
  for (int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) return false;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int k, n, res = 0, cards = 0;
  cin >> n >> k;
  long long int arr[26] = {0};
  string s;
  cin >> s;
  for (long long int i = 0; i < s.size(); i++) {
    arr[s[i] - 'A']++;
  }
  sort(arr, arr + 26);
  int i = 25;
  while (1) {
    if (arr[i] <= k - cards) {
      res += arr[i] * arr[i];
      cards += arr[i];
    } else {
      res += (k - cards) * (k - cards);
      break;
    }
    --i;
  }
  cout << res;
  return 0;
}
