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