#include <bits/stdc++.h>
using namespace std;
int n, k;
char ch;
int all[29];
int id[32];
bool cmp(const int &a, const int &b) { return all[a] > all[b]; }
int main() {
  while (cin >> n >> k) {
    for (int i = 0; i < 30; ++i) id[i] = i;
    memset(all, 0, sizeof(all));
    for (int i = 0; i < n; ++i) {
      cin >> ch;
      all[ch - 'A']++;
    }
    sort(id, id + 26, cmp);
    long long ans = 0, num = 0;
    for (int i = 0; i < 26; ++i) {
      num += all[id[i]];
      if (num < k) {
        ans += (long long)all[id[i]] * all[id[i]];
      }
      if (num >= k) {
        ans += (k - num + all[id[i]]) * (k - num + all[id[i]]);
        num = k;
        break;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
