#include <bits/stdc++.h>
using namespace std;
long long a[26];
int main() {
  long long n, k;
  cin >> n >> k;
  string s1;
  cin >> s1;
  for (long long i = 0; i < n; ++i) ++a[s1[i] - 'A'];
  sort(a, a + 26);
  reverse(a, a + 26);
  long long sum = 0;
  for (long long i = 0; i < 26; ++i) {
    long long x = min(a[i], k);
    sum += x * x;
    k -= x;
  }
  cout << sum << endl;
  return 0;
}
