Ishaan's Birthday
Submissions: 252   Accuracy:

34.94%

  Difficulty: Easy   Marks: 2

Ishaan's birthday is coming. His friend Charul decides to gift him uppercase English Alphabets. Since Ishaan likes being organised, he doesn't like different alphabets. He wants to make all the alphabets same.
To exchange an alphabet with another, it costs him the difference in their ASCII value. For example, to exchange A with C, it will cost him 67-65 = 2.
He doesn't want to spend to much money, so help him calculate the minimum amount he must spend to make all the alphabets same.

Input : 
First line of input contains a single integer T denoting the number of test cases.
The only line contains 26 space-separated integers denoting the number of alphabets. The first integer denotes the number of A's, second denotes number of B's and so on.

Output : 
For each test case, print the required answer in a new line.

Constraints : 
1 <= T <= 200
1 <= Total number of alphabets <= 26*(10^5)

Example : 
Input : 

3
2 3 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 3 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
3 4 0 0 0 0 0 0 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Output : 
6
3
45

Explanation : 
Case 1 : 

Exchanging all the alphabets to B will cost the minimum.
Exchanging 2 A's for B's : 2 * (66-65) = 2
Exchanging 4 C's for B's : 4 * (67-66) = 4
Total cost = 6

Case 2 : 
Exchanging all the alphabets to C will cost the minimum.
Exchanging 3 B's for C's : 3 * (67-66) = 3
Total cost = 3

Case 3 : 
Exchanging all the alphabets to B will cost the minimum.
Exchanging 3 A's for B's : 3 * (66-65) = 3
Exchanging 6 I's for B's : 6 * (73-66) = 42
Total cost = 45

 

** For More Input/Output Examples Use 'Expected Output' option **

Author: goyalanubhav11


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.