AlgoUniversity
  • Go Back
Discussion
Count Good Subarrays :

Author

Ayush Gangwani

Difficulty Level : Medium

Submissions : 272

Asked In : CodeNation Trilogy-Innovations

Marks :15

: 3 | : 0

A good array is an array if you can reduce it to an array of zeroes by using the following move :

  • Select any two elements and subtract $$$2^i$$$ from each element if their $$$bitwise-AND$$$ contains $$$1$$$ at $$$i-th$$$ bit.

You are given an array $$$A$$$ containing $$$n$$$ non negative integers. Now you need to find the number of good subarrays in array $$$A$$$. Since the number can be very large print the answer modulo $$$10^9 + 7$$$.

Input

The first line of input contains an integer $$$t \hspace{2pt} (1 \le t \le 10^4)$$$ — the number of testcases. The description of $$$t$$$ testcases follows.

The first line of each testcase contains an integer $$$n \hspace{2pt} (1 \le n \le 10^5)$$$ — the number of elements in the array $$$A$$$.

The second line of each testcase contains $$$n$$$ space separated integers $$$a_0, a_1, ... a_n$$$ $$$(0 \le a_i \le 10^9)$$$ — the elements of array $$$A$$$.

It is guaranteed that the sum of $$$n$$$ over all testcases does not exceed $$$10^5.$$$

Output

For each testcase, print a single integer — the number of good subarrays of array $$$A$$$ modulo $$$10^9 + 7$$$.

Example

Input
1
4
1 0 3 2
Output
2

Note

In sample testcase 1,

  • subarray $$$[0]$$$ is already good.
  • subarray $$$[1,0,3,2]$$$ can be made a good array, by subtracting $$$2$$$, from index $$$3$$$ and $$$4$$$ since their bitwise AND is $$$2$$$. and $$$1$$$ can be subtracted from index $$$1$$$ and index $$$3$$$ since their $$$bitwise-AND$$$ is $$$1$$$.

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.