public void solve() throws IOException {
    int n = nextInt();
    int k = nextInt();

    Letter[] letters = new Letter[26];
    for (int x = 0; x < 26; x++) {
      letters[x] = new Letter((char) (x + 65));
    }

    String cards = nextLine();
    for (int x = 0; x < n; x++) {
      letters[cards.charAt(x) - 65].addCount();
    }
    Arrays.sort(letters);

    int total = 0;
    for (int x = 0; x < 26; x++) {
      int count = Math.min(k, letters[x].count);
      total += count * count;
      k -= count;
      if (k == 0) {
        break;
      }
    }
    System.out.println(total);
  }