#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    map<char, long long> m;
    vector<pair<long long, char> > v;
    for (long long i = 0; i < (int)((s).size()); i++) {
      m[s[i]]++;
    }
    map<char, long long>::iterator itr;
    for (itr = m.begin(); itr != m.end(); itr++) {
      v.push_back({itr->second, itr->first});
    }
    sort(v.begin(), v.end());
    map<char, long long> mm;
    long long sum = 0;
    for (long long i = 0; i < v.size(); i++) {
      if (v[v.size() - 1 - i].first >= k) {
        mm.insert({v[v.size() - i - 1].second, k});
        sum += k * k;
        k = 0;
      } else {
        mm.insert({v[v.size() - 1 - i].second, v[v.size() - 1 - i].first});
        sum += v[v.size() - 1 - i].first * v[v.size() - 1 - i].first;
        k -= v[v.size() - 1 - i].first;
      }
      if (k <= 0) break;
    }
    cout << sum;
  }
}
