#include <bits/stdc++.h>
using namespace std;
bool cmp(int a, int b) { return a > b; }
int main() {
  int n, k;
  int i, j;
  char c;
  long long int a[26];
  long long int sum, ans = 0;
  while (cin >> n >> k) {
    for (i = 0; i <= 25; i++) a[i] = 0;
    for (i = 0; i < n; i++) {
      cin >> c;
      a[c - 'A']++;
    }
    sort(a, a + 26, cmp);
    ans = 0;
    sum = a[0];
    for (i = 0; sum <= k;) {
      ans += a[i] * a[i];
      sum += a[++i];
    }
    sum -= a[i];
    ans += (k - sum) * (k - sum);
    cout << ans << endl;
  }
  return 0;
}
