AND Palindromes
You are given an array
consisting of integers. Calculate the number of ways to divide this array into subsegments, such that the sequence formed by taking bitwise AND in each segment of the partition is a palindrome.
A partition is palindromic if for every . Your task is to calculate the number of palindromic partitions. Since this number can be large, calculate it modulo .
Input Format
- The first line of input contains — 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 number of ways to partition into subsegments, such that the bitwise AND of these segments form a palindrome.
Constraints
- Sum of over all test cases is at most .
Sample Input 1
3
3
1 1 1
4
3 4 5 6
5
1 1 0 1 0
Sample Output 1
4
1
4
Explanation
Test case : The palindromic partitions are . To see why:
- For ,
- For ,
- For ,
- For ,
Clearly is a palindrome in all cases.
Test case : The only palindromic partition is .
Test case : The palindromic partitions are .
Comments
Post a Comment