Count how many existing numbers differ from a given number in at most bit positions.
Problem
You are given an integer and a limit . Then you are given integers representing numbers already in the game, and one special integer representing Fedor's number.
For every given number, compare its binary representation with . A number is considered compatible if the two numbers differ in at most bit positions. Your task is to count how many of the numbers are compatible with .
In other words, for each number , compute the number of set positions where the bits of and are different, and count it if that value is at most .
Input Format
- The first line contains three integers , , and .
- The second line contains integers .
- The third line contains one integer .
Output Format
- Print a single integer: the number of values among that differ from in at most bit positions.
Constraints
Example 1
Input
3 4 1 1 2 3 2
Output
2
Explanation
Compare each value with 2:
- 1 differs in 2 bit positions
- 2 differs in 0 bit positions
- 3 differs in 1 bit position So the answer is 2.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.