#B2087. Count Occurrences in an Integer Sequence
Count Occurrences in an Integer Sequence
Count Occurrences in an Integer Sequence
Given a sequence of integers and a specified target integer, count the number of occurrences of the target integer in the sequence.
Input: The first line contains two integers n and x, where n is the number of elements in the sequence and x is the target integer. The second line contains n space-separated integers representing the sequence.
Output: Output a single integer, which is the count of numbers in the sequence equal to x.
The problem can be expressed using the formula: \(\text{count} = \sum_{i=1}^{n} \mathbf{1}_{\{a_i = x\}}\), where \(\mathbf{1}_{\{a_i = x\}}\) is an indicator function that equals 1 when \(a_i = x\) and 0 otherwise.
inputFormat
The input consists of two lines:
- The first line contains two space-separated integers: n (the number of elements) and x (the target integer).
- The second line contains n space-separated integers.
outputFormat
Output a single integer: the number of elements in the sequence that are equal to x.
sample
5 2
1 2 3 2 4
2