#include <bits/stdc++.h>
using namespace std;
bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.first > b.first);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  t = 1;
  while (t--) {
    long long int n, p;
    cin >> n >> p;
    string s;
    cin >> s;
    map<char, long long int> mymap;
    for (long long int i = 0; i < n; i++) mymap[s[i]]++;
    vector<pair<long long int, long long int>> myvec;
    for (auto i : mymap) myvec.push_back(make_pair(i.second, i.first));
    sort(myvec.begin(), myvec.end(), sortinrev);
    long long int ans = 0;
    for (auto i : myvec) {
      if (i.first <= p) {
        ans += i.first * i.first;
        p -= i.first;
      } else {
        ans += (p * p);
        break;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
