You are given a string S of N lowercase English letters, representing letter candles in a box. You are allowed to remove at most M candles.
The "cost" of the box is calculated based on the frequencies of the characters it contains. The formula for the cost is the sum of the squares of the counts of each unique character. For example, if the box contains "aabc", the counts are a=2, b=1, c=1, so the cost is 2^2 + 1^2 + 1^2 = 6.
Your task is to find the minimum possible cost of the box after removing at most M candles.
Input Format:
The first line of input contains the integer N, the initial number of candles.
The second line contains the integer M, the maximum number of candles you can remove.
The third line contains the N-letter string S.
Output Format:
Print a single integer representing the minimum achievable cost.
Note:
The key insight is to use a greedy strategy. The reduction in cost is greatest when you remove a candle from the character group that is currently the most frequent.
A priority queue (max-heap) is the ideal data structure to efficiently find the most frequent character group at each step of the removal process.