#include <bits/stdc++.h>
using namespace std;
const int siz = 1e5 + 7;
const int siz2 = 2e5 + 7;
int n;
long long k, Ans;
string s;
map<char, int> mp;
vector<pair<long long, char> > v;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k >> s;
  for (int i = 0; i < n; ++i) mp[s[i]]++;
  for (auto it : mp) {
    v.push_back({it.second, it.first});
  }
  sort(v.rbegin(), v.rend());
  for (auto it : v) {
    if (!k) break;
    if (it.first <= k) {
      Ans += (it.first * it.first);
      k -= it.first;
    } else {
      Ans += (k * k);
      k -= k;
    }
  }
  cout << Ans;
  return 0;
}
