You are given an array
, consisting of integers. In one move, you can take two adjacent numbers and , delete them, and then insert the number at the deleted position. Here, denotes bitwise AND. Note that after this operation, the length of the array decreases by one.
Formally, as long as (where denotes the current length of ), you can pick an index and transform into .
Find the minimum number of moves required to make all numbers in the resulting array equal.
Input Format
- The first line of input contains an integer — the number of test cases you need to solve.
- The first line of each test case contains one integer , the size of the array.
- The second line of each test case contains space-separated integers — the elements of the array .
Output Format
For each test case, output on a new line the minimum number of moves required to make all numbers equal.
Constraints
- Sum of over all test cases is at most .
Subtasks
- Subtask 1 (20 points):
- Sum of over all test cases is at most .
- Subtask 2 (30 points):
- Sum of over all test cases is at most .
- Subtask 3 (50 points):
- Original constraints.
Sample Input 1
4
4
0 0 0 1
2
1 1
6
1 2 3 4 5 6
4
2 28 3 22
Sample Output 1
1
0
4
3
Explanation
Test case : Choose to make the array .
Test case : All elements of the array are already equal.
Test case : One possible sequence of moves is as follows:
- Choose , making the array
- Choose , making the array
- Choose , making the array
- Choose , making the array
It can be verified that in this case, making every element equal using or fewer moves is impossible.
No comments:
Post a Comment