#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  vector<long long> v;
  map<char, int> mp;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    mp[s[i]]++;
  }
  int i = 0;
  for (auto it : mp) {
    v.push_back(it.second);
  }
  sort(v.rbegin(), v.rend());
  for (int i = 0; i < n && k > 0; i++) {
    sum += min(k, v[i]) * min(k, v[i]);
    k -= min(k, v[i]);
  }
  cout << sum << endl;
}
