#include <bits/stdc++.h>
using namespace std;
long long n, k, hitung, counter[100002], hasil, nilai, indeks, banyak;
char data[100002], op, patok;
bool bol[100002];
int main() {
  scanf("%I64d %I64d", &n, &k);
  scanf("%c", &op);
  for (long i = 0; i < n; i++) {
    scanf("%c", &data[i]);
  }
  sort(data, data + n);
  patok = data[0];
  hitung = 0;
  nilai = 0;
  counter[0] = 1;
  for (long i = 1; i < n; i++) {
    if (data[i] == patok) {
      counter[hitung] = counter[hitung] + 1;
    } else {
      patok = data[i];
      hitung = hitung + 1;
      counter[hitung] = 1;
    }
  }
  for (long i = 0; i <= hitung; i++) {
    bol[i] = true;
  }
  while (k > 0) {
    hasil = 0;
    indeks = 0;
    for (long j = 0; j <= hitung; j++) {
      if (counter[j] >= hasil && bol[j] == true) {
        hasil = counter[j];
        indeks = j;
      }
    }
    bol[indeks] = false;
    if (k - hasil <= 0) {
      hasil = k;
      k = 0;
    } else {
      k = k - hasil;
    }
    nilai = nilai + hasil * hasil;
    if (k == 0) {
      break;
    }
  }
  printf("%I64d\n", nilai);
}
