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