#include <bits/stdc++.h>
using namespace std;
int a[100];
bool cmp(int x, int y) { return x > y; }
int main() {
  int n, k;
  char c;
  long long sum = 0;
  scanf("%d %d", &n, &k);
  getchar();
  for (int i = 0; i < n; i++) {
    scanf("%c", &c);
    a[c]++;
  }
  sort(&a[65], &a[65] + 26, cmp);
  int flag = 0;
  for (int i = 0; flag < k; i++) {
    sum += (long long)min(k - flag, a[i + 65]) * min(k - flag, a[i + 65]);
    flag += min(k - flag, a[i + 65]);
  }
  printf("%I64d", sum);
}
