#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300500;
long long k, n, arr[300];
vector<long long> mas;
string s;
inline bool cmp(const long long& a, const long long& b) { return a > b; }
int main() {
  cin >> n >> k;
  cin >> s;
  for (int i = 0; i < n; ++i) {
    ++arr[s[i]];
  }
  for (int i = 0; i < 300; ++i) {
    mas.push_back(arr[i] * 1LL);
  }
  sort(mas.begin(), mas.end(), &cmp);
  long long ans = 0;
  for (int i = 0; i < (int)mas.size(); ++i) {
    if (k < mas[i]) {
      ans += k * k;
      break;
    } else {
      ans += mas[i] * mas[i];
      k -= mas[i];
    }
  }
  printf("%I64d\n", ans);
  return 0;
}
