#include <bits/stdc++.h>
const int maxn = (int)1e6;
const int mod = (int)1e9 + 7;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  long long n, k, cnt = 0, cnt2 = 0, ans = 0;
  bool ok = false;
  string s;
  cin >> n >> k;
  cin >> s;
  long long a[26] = {0};
  for (int i = 0; i < n; i++) a[s[i] - 'A']++;
  sort(a, a + 26);
  for (int i = 25; i >= 0; i--) {
    if (a[i] <= k) {
      ans += (a[i] * a[i]);
      k -= a[i];
    } else {
      ans += (k * k);
      break;
    }
  }
  cout << ans;
  return 0;
}
