#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7FFFFFFF;
struct point_int {
  int x, y;
  point_int() {}
  point_int(int a, int b) { x = a, y = b; }
};
struct point_double {
  double x, y;
  point_double() {}
  point_double(double a, double b) { x = a, y = b; }
};
struct Node {
  int v, w;
  Node() {}
  bool operator<(const Node &a) const { return w > a.w; }
  Node(int _v, int _w) { v = _v, w = _w; }
};
template <class T>
T gcd(T a, T b) {
  return b == 0 ? a : gcd(b, a % b);
}
template <typename T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <class T>
T big_mod(T n, T p, T m) {
  if (p == 0) return (T)1;
  T x = big_mod(n, p / 2, m);
  x = (x * x) % m;
  if (p & 1) x = (x * n) % m;
  return x;
}
template <class T>
T multiplication(T n, T p, T m) {
  if (p == 0) return (T)0;
  T x = multiplication(n, p / 2, m);
  x = (x + x) % m;
  if (p & 1) x = (x + n) % m;
  return x;
}
template <class T>
T my_pow(T n, T p) {
  if (p == 0) return 1;
  T x = my_pow(n, p / 2);
  x = (x * x);
  if (p & 1) x = (x * n);
  return x;
}
template <class T>
double getdist(T a, T b) {
  return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
template <class T>
T extract(string s, T ret) {
  stringstream ss(s);
  ss >> ret;
  return ret;
}
template <class T>
string tostring(T n) {
  stringstream ss;
  ss << n;
  return ss.str();
}
template <class T>
inline T Mod(T n, T m) {
  return (n % m + m) % m;
}
template <class T>
T MIN3(T a, T b, T c) {
  return min(a, min(b, c));
}
template <class T>
T MAX3(T a, T b, T c) {
  return max(a, max(b, c));
}
template <class T>
void print_vector(T &v) {
  int sz = v.size();
  if (sz) cout << v[0];
  for (int i = 1; i < sz; i++) cout << ' ' << v[i];
  cout << endl;
}
bool isVowel(char ch) {
  ch = toupper(ch);
  if (ch == 'A' || ch == 'U' || ch == 'I' || ch == 'O' || ch == 'E')
    return true;
  return false;
}
bool isConsonant(char ch) {
  if (isalpha(ch) && !isVowel(ch)) return true;
  return false;
}
int read_int() {
  int n;
  scanf("%d", &n);
  return n;
}
int read_LLD() {
  long long int n;
  scanf("%lld", &n);
  return n;
}
inline int buffer_input() {
  char inp[1000];
  scanf("%s", inp);
  return atoi(inp);
}
map<char, int> Map;
map<char, int>::iterator it;
int main() {
  int N, K;
  cin >> N >> K;
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    Map[s[i]]++;
  }
  vector<int> v;
  for (it = Map.begin(); it != Map.end(); it++) {
    v.push_back((*it).second);
  }
  sort(v.rbegin(), v.rend());
  long long int ans = 0;
  for (int i = 0; i < v.size(); i++) {
    long long int take = min(K, v[i]);
    ans += (take * take);
    K -= take;
  }
  cout << ans << endl;
  return 0;
}
