#include <bits/stdc++.h>
using namespace std;
long long int n, k;
char str[200100];
long long int LET[26];
long long int a[26];
int main() {
  cin >> n >> k;
  cin >> str;
  for (long long int i = 0; i < n; i++) {
    LET[str[i] - 'A']++;
  }
  for (long long int i = 0; i < 26; i++) a[i] = LET[i];
  long long int ans = 0;
  sort(a, a + 26);
  for (long long int i = 25; i >= 0 && k; i--) {
    if (k >= a[i]) {
      ans += a[i] * a[i];
      k -= a[i];
    } else {
      ans += k * k;
      k = 0;
    }
  }
  cout << ans << endl;
  return 0;
}
