Count how many existing numbers differ from a given number in at most bit positions.
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 .
Example 1
Input
3 4 1 1 2 3 2
Output
2
Explanation
Compare each value with 2:
Premium problem context
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.