#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 + 1;
const int INF = 1000000000;
int main() {
  map<char, int> f;
  int n, k;
  cin >> n >> k;
  for (int i = 'A'; i <= 'Z'; i++) {
    f[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    char c;
    cin >> c;
    f[c]++;
  }
  long long ans = 0;
  vector<int> freq;
  for (int i = 'A'; i <= 'Z'; i++) {
    freq.push_back(f[i]);
  }
  sort(freq.rbegin(), freq.rend());
  for (int i = 0; i < freq.size(); i++) {
    if (freq[i] <= k) {
      k -= freq[i];
      ans += (long long)freq[i] * freq[i];
    } else {
      ans += (long long)k * k;
      break;
    }
  }
  cout << ans;
  return 0;
}
