#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, k;
  cin >> n >> k;
  map<char, long long> mp;
  for (long long i = 0; i < n; i++) {
    char x;
    cin >> x;
    mp[x]++;
  }
  vector<pair<long long, char>> v;
  for (auto it : mp) {
    pair<long long, char> p;
    p.first = it.second;
    p.second = it.first;
    v.push_back(p);
  }
  sort(v.begin(), v.end(), greater<pair<long long, char>>());
  long long ans = 0;
  for (long long i = 0; i < v.size() && k > 0; i++) {
    long long x = min(k, v[i].first);
    ans += (x * x);
    k -= x;
  }
  cout << ans << endl;
  return 0;
}
