Skip to main content
Back to problems
Codeforces
Easy
Bit Manipulation
Arrays
Math
Fedor and New Game

Count how many existing numbers differ from a given number in at most kk bit positions.

Acceptance 0%
Problem Statement

Problem

You are given an integer nn and a limit kk. Then you are given nn integers representing numbers already in the game, and one special integer ff representing Fedor's number.

For every given number, compare its binary representation with ff. A number is considered compatible if the two numbers differ in at most kk bit positions. Your task is to count how many of the nn numbers are compatible with ff.

In other words, for each number aia_i, compute the number of set positions where the bits of aia_i and ff are different, and count it if that value is at most kk.

Input Format

  • The first line contains three integers nn, mm, and kk.
  • The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n.
  • The third line contains one integer ff.

Output Format

  • Print a single integer: the number of values among a1,a2,…,ana_1, a_2, \dots, a_n that differ from ff in at most kk bit positions.

Constraints

  • 1≤n≤10001 \le n \le 1000
  • 1≤m≤101 \le m \le 10
  • 0≤k≤m0 \le k \le m
  • 0≤ai,f<2m0 \le a_i, f < 2^m
Examples
Sample cases returned by the problem API.

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.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.