The maximum number

3

57 votes
Basic Programming, Bit Manipulation, Bit manipulation, Math, Sorting
Problem

You are given an array A of n elements A1,A2,A3, ...,An. Let us define a function F(x)=ni=1Ai&x.

Note: Here, & represents bitwise AND operator.

You are required to find the number of different values of x for which F(x) is maximized. There exists a condition for x that it must have exactly l bits sets in its binary representation.

Your task is to find a number of such values for which this function is maximized. Print the required number.

If there are infinite such numbers, then print -1.

It can be proved that under the given constraints the value to be printed is either infinite or not greater than 1e18.

Input format

  • The first line contains the number of test cases, T.
  • The second line contains two space-separated integers n and l (as described in the problem).
  • The third line contains n space seprated integers A1,A2,A3.....An.

Output format

There are Tlines of the output. The only line of output for each test case contains a single integer as described in the problem statement.

Constraints

1T1000

1l30

1N20000

1A[i]1e9

It is guaranteed that sum of N over all test cases will not exceed 2e5.

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For the first test case both 5 and 6 can serve the purpose while in second test case only 4 satisfies the constraints.

Editor Image

?