k-Intersecting pair

View as PDF

Submit solution

Points: 12
Time limit: 1.5s
Memory limit: 256M

Author:
Problem type

jsumabat has n integers, and has a definition of what he calls k-Intersecting Numbers.

He considers a pair of integers "k-Intersecting" if the binary representation of the numbers x and y differs from each other in exactly k bits.

For example, if k = 2, the pairs of integers x = 5 and y =3 is k-intersecting because the binary representation x=101 and y=011 differs exactly in two bits.

Now here's the problem: jsumabat wants to know how many pairs of integers (i, j) are in his sequence so that i < j and the pair of integers a_i and a_j is k-intersecting.

Can you help jsumabat find the number of pairs that fit in these constraints?

Input Specifications

The first line contains two integers n and k (2 \le n \le 10^5, 0 \le k \le 14) - the number of integers jsumabat has and the number of bits in which integers in a k-intersecting pair should differ.

The second line contains the sequence a_1, a_2, \dots, a_n (0 \le a_i \le 10^4), which jsumabat has.

Output Specifications

Print the number of pairs (i, j) so that i < j and the pair of integers a_i and a_j is k-intersecting.

Sample Input 1

4 1
0 3 2 1

Sample Output 1

4

Sample Input 2

6 0
200 100 100 100 200 200

Sample Output 2

6

Sample Explanation

In the first sample, there are 4 k-intersecting pairs:

  • (1, 3),
  • (1, 4),
  • (2, 3),
  • (2, 4).

In the second sample where k=0, there are 6 k-intersecting pairs:

  • (1, 5),
  • (1, 6),
  • (2, 3),
  • (2, 4),
  • (3, 4),
  • (5, 6).

Comments

There are no comments at the moment.