#include <bits/stdc++.h>
using namespace std;
bool revSort(long long a, long long b) { return (a > b); }
int main() {
  long long n, k;
  long long num[26];
  cin >> n >> k;
  for (long long i = 0; i < 26; i++) num[i] = 0;
  for (long long i = 0; i < n; i++) {
    char card;
    cin >> card;
    num[card - 'A']++;
  }
  sort(num, num + 26, revSort);
  long long index = 0;
  long long answer = 0;
  while (k > 0) {
    long long current = min(k, num[index]);
    answer += current * current;
    k -= current;
    index++;
  }
  cout << answer << endl;
  return 0;
}
