#include <bits/stdc++.h>
using namespace std;
unordered_map<char, long long> store;
class thisway {
 public:
  bool operator()(const char& a, const char& b) {
    if (store[a] > store[b]) return true;
    return false;
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  for (long long i = 0; i < n; i++) {
    store[s[i]]++;
  }
  multiset<char, thisway> ss;
  for (auto x : store) ss.insert(x.first);
  long long sum = 0;
  while (!ss.empty() && k > 0) {
    long long pp = store[*(ss.begin())];
    ss.erase(ss.begin());
    long long req = min(k, pp);
    sum += req * req;
    pp -= req;
    k -= req;
    if (pp == 0) store.erase(pp);
  }
  cout << sum << "\n";
  return 0;
}
