#include <bits/stdc++.h>
using namespace std;
class s1 {
 public:
  s1() {
    int n;
    scanf("%d\n", &n);
    char db[100][100];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        scanf("%c", &db[i][j]);
      }
      scanf("\n");
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        int ct = 0;
        int a = i - 1;
        int b = i + 1;
        int c = j - 1;
        int d = j + 1;
        if (a >= 0)
          if (db[a][j] == 'o') ct++;
        if (b <= n - 1)
          if (db[b][j] == 'o') ct++;
        if (c >= 0)
          if (db[i][c] == 'o') ct++;
        if (d <= n - 1)
          if (db[i][d] == 'o') ct++;
        if (ct == 1 || ct == 3) {
          printf("NO");
          return;
        }
      }
    }
    printf("YES");
  }
};
class s2 {
 public:
  s2() {
    int n, k;
    char d[100001];
    vector<unsigned long long int> s;
    for (int i = 0; i < 26; i++) s.push_back(0);
    scanf("%d %d\n", &n, &k);
    scanf("%s", d);
    for (int i = 0; i < n; i++) {
      s[d[i] - 'A']++;
    }
    sort(s.begin(), s.end(), greater<unsigned long long int>());
    for (int i = 0; i < n; i++) {
    }
    unsigned long long int t = 0;
    int c = 0;
    int m = 0;
    while (m < k) {
      if (m + s[c] <= k) {
        t += s[c] * s[c];
        m += s[c];
        c++;
      } else {
        unsigned long long int o = k - m;
        t += (o) * (o);
        m = k;
      }
    }
    cout << t;
  }
};
class s3 {
 public:
  s3() {}
};
int main() {
  s2* cS2 = new s2();
  return 0;
}
