#include <bits/stdc++.h>
using namespace std;
long long freq[26];
bool cmp(int x, int y) { return x > y; }
int main() {
  long long n, k;
  string str;
  cin >> n >> k >> str;
  for (int i = 0; i < str.length(); i++) freq[(int)str[i] - (int)('A')]++;
  sort(freq, freq + 26, cmp);
  long long sum = 0;
  for (int i = 0; i < str.length(); i++) {
    if (k > freq[i])
      sum += freq[i] * freq[i], k -= freq[i];
    else {
      sum += k * k;
      break;
    }
  }
  cout << sum << endl;
  return 0;
}
