#include <bits/stdc++.h>
using namespace std;
const double EPS = 10e-8;
const int MAX = 100005;
const int INF = 1 << 30;
long long B[26];
int main(int argc, char **argv) {
  int n, k;
  scanf("%d %d\n", &n, &k);
  memset(B, 0, sizeof B);
  for (int i = 0; i < n; i++) {
    char ch = getchar();
    B[ch - 'A']++;
  }
  sort(B, B + 26);
  long long ans = 0;
  for (int i = 25; i >= 0; i--) {
    if (k >= B[i]) {
      ans += B[i] * B[i];
      k -= B[i];
    } else {
      long long p = 1ll * k * k;
      ans += p;
      break;
    }
  }
  cout << ans;
  return EXIT_SUCCESS;
}
