#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, ans = 0;
  int arr[26]{};
  cin >> n >> m;
  string s;
  cin >> s;
  for (int i = 0; i < n; i++) {
    arr[s[i] - 'A']++;
  }
  sort(arr, arr + 26);
  int j = 25;
  while (m > 0) {
    if (arr[j] > 0) {
      if (arr[j] >= m) {
        ans += (long long)m * m;
        cout << ans;
        return 0;
      } else {
        ans += (long long)arr[j] * arr[j];
        m -= arr[j];
      }
    }
    j--;
  }
}
