#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 10;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const long long inf = -1e18;
long long n, k, ans;
map<char, long long> us, color;
vector<long long> vec;
string str;
int main() {
  cin >> n >> k;
  cin >> str;
  for (int i = 0; i < str.size(); i++) us[str[i]]++;
  for (int i = 0; i < str.size(); i++) {
    if (color[str[i]] == 0) {
      vec.push_back(us[str[i]]);
      color[str[i]] = 1;
    }
  }
  sort(vec.begin(), vec.end());
  while (k) {
    ans += min(k, vec.back()) * min(k, vec.back());
    k -= min(k, vec.back());
    vec.pop_back();
  }
  cout << ans;
  return 0;
}
