All problems

Problem 783

Count Occurrences of a Value

Easy · 10 pts · Array, Basics

Problem

Count how many times the value X appears in the array. Walk through the array once and add one to a counter every time an element equals X. The answer is 0 if X does not appear at all. This is the basic counting loop that many harder problems build on.

Input

The first line contains N and X. The second line contains the N array elements.

Output

Print the number of elements equal to X.

Constraints

1 <= N <= 100000; -10^9 <= A[i], X <= 10^9

Example input

5 3
3 1 3 3 2

Example output

3

Explanation

In 3 1 3 3 2 with X = 3, the value 3 appears at positions 0, 2 and 3, so it appears 3 times.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Count Even and Odd Elements Next: Linear Search