#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i = 0, j, k, m, n, l = 0, f = 0;
  cin >> n >> m;
  string a;
  cin >> a;
  int b[26] = {0};
  for (i = 0; i < n; i++) {
    b[a[i] - 'A']++;
  }
  while (m > 0) {
    f = 0;
    for (i = 0; i < 26; i++) {
      if (b[i] > b[f]) f = i;
    }
    if (b[f] <= m) {
      l += pow(b[f], 2);
      m = m - b[f];
      b[f] = 0;
    } else {
      l += pow(m, 2);
      m = 0;
    }
  }
  cout << l << endl;
}
