#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  long long arr[26] = {0};
  for (long long i = 0; i < s.size(); i++) {
    arr[s[i] - 'A']++;
  }
  sort(arr, arr + 26);
  reverse(arr, arr + 26);
  long long i = 0;
  long long sum = 0;
  while (k > 0) {
    if (arr[i] <= k) {
      sum += arr[i] * arr[i];
      k = k - arr[i];
    } else {
      sum += k * k;
      break;
    }
    i++;
  }
  cout << sum;
  return 0;
}
