#include <bits/stdc++.h>
using namespace std;
multimap<unsigned long long int, char> sort_map(
    map<char, unsigned long long int>& M) {
  multimap<unsigned long long int, char> MM;
  for (auto& it : M) {
    MM.insert({it.second, it.first});
  }
  return MM;
}
int main() {
  unsigned long long int k;
  int n;
  char c;
  cin >> n;
  cin >> k;
  map<char, unsigned long long int> M;
  for (int i = 0; i < n; i++) {
    cin >> c;
    M[c] += 1;
  }
  auto MM = sort_map(M);
  unsigned long long int total = 0;
  for (auto it = MM.rbegin(); it != MM.rend(); it++) {
    if (k > it->first) {
      k -= it->first;
      total += it->first * it->first;
    } else {
      total += k * k;
      k = 0;
      break;
    }
  }
  cout << total;
  return 0;
}
