You are given an array A consisting of N distinct integers. If the size of the array is greater than one, then you can perform the following operations any number of times:
Select two integers Ai and Aj such that CountOnes(Ai⊕Aj)=1 and delete either Ai or Aj from the array. This operation costs C1.
Select two integers Ai and Aj such that CountOnes(Ai⊕Aj)>1 and delete either Ai or Aj from the array. This operation costs C2.
Here, CountOnes(X) returns the number of 1s available in the binary representation of integer X. Determine the minimum cost to reduce the size of the array to 1.
Input format
Output format
For each test case, print a single integer in a separate line as described in the problem statement
Constraints
1≤T≤20
1≤N≤104
1≤C1,C2,Ai≤109
Subtasks
We take 1 and 3 and delete 1 with cost 50. Next we take 3 and 2 and delete 2 with cost 50. Last, we take 3 and 4 and delete 4 with cost 100.
So total cost = 50+50+100 = 200