CF BUDDY
← Problems·

1829H · Don't Blame Me

1700 · bitmasks, combinatorics, dp

Problem: Sadly, the problem setter couldn't think of an interesting story, thus he just asks you to solve the following problem.

Given an array aa consisting of nn positive integers, count the number of non-empty subsequences for which the bitwise AND\mathsf{AND} of the elements in the subsequence has exactly kk set bits in its binary representation. The answer may be large, so output it modulo 109+710^9+7.

Recall that the subsequence of an array aa is a sequence that can be obtained from aa by removing some (possibly, zero) elements. For example, [1,2,3][1, 2, 3], [3][3], [1,3][1, 3] are subsequences of [1,2,3][1, 2, 3], but [3,2][3, 2] and [4,5,6][4, 5, 6] are not.

Note that AND\mathsf{AND} represents the bitwise AND operation.

Input Format: Each test contains multiple test cases. The first line contains the number of test cases tt (1t1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case consists of two integers nn and kk (1n21051 \leq n \leq 2 \cdot 10^5, 0k60 \le k \le 6) — the length of the array and the number of set bits that the bitwise AND\mathsf{AND} the counted subsequences should have in their binary representation.

The second line of each test case consists of nn integers aia_i (0ai630 \leq a_i \leq 63) — the array aa.

It is guaranteed that the sum of nn over all test cases doesn't exceed 21052 \cdot 10^5.

Output Format: For each test case, output a single integer — the number of subsequences that have exactly kk set bits in their bitwise AND\mathsf{AND} value's binary representation. The answer may be large, so output it modulo 109+710^9+7.

Sample Cases

Case 1

Input

6
5 1
1 1 1 1 1
4 0
0 1 2 3
5 1
5 5 7 4 2
1 2
3
12 0
0 2 0 2 0 2 0 2 0 2 0 2
10 6
63 0 63 5 5 63 63 4 12 13

Output

31
10
10
1
4032
15

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback