407328: GYM102766 B Singhal and Equality
Description
If you want to practice topicwise questions in the ladder way like a2oj , do register on my site http://codedigger.tech after the contest. Here you will get Handpicked Topicwise Questions from codeforces, codechef, uva and spoj for your better practice. Best of Luck.
Singhal loves Equality. He has a string $$$S$$$ consisting of lowercase English Letters.
He wants to equalize the frequency of all distinct characters in his string $$$S$$$. He can do the following operation any number of times: pick any single character in the string and replace with another lowercase English alphabet.
He wants to perform minimum number of operations to equalize the frequency of distinct characters.
Frequency of a character is number of times it appear in the string.
InputThe first line contains a single integer $$$t (1 \le t \le 10^5)$$$ — the number of test cases in the input. Then $$$t$$$ test cases follow.
Each query contains a single string consisting of lowercase English letters $$$S (1 \le |S| \le 10^5)$$$. $$$|S|$$$ is the length of the string.
It is guaranteed that the total sum of $$$|S|$$$ is at most $$$10^5$$$.
OutputPrint $$$t$$$ answers to the test cases. Each answer must be consisting of single integer — the minimum number of operations required to equalize the frequency of distinct characters of string.
ExampleInput6 aba abba abbc abbbc codedigger codealittleOutput
1 0 1 2 2 3Note
In the first query — We can replace letter $$$b \to a$$$ to form aaa. Now frequency of all distinct character is same i.e. $$$3$$$ or another possibility is replace one $$$a \to c$$$ to form abc. In this case frequency is $$$1$$$.
In the second query — Frequency of all distinct character is Same i.e. $$$2$$$. No need to apply operation.