SDE Path

Count Occurrences in a Sorted Array

Easy

Count Occurrences in a Sorted Array

Count how many times a target value occurs in a sorted array using binary search boundaries.

Input format

The first line contains N and the target. The second line contains N integers in non-decreasing order.

Output format

Print how many times the target occurs.

Constraints

  • Values fit in a 64-bit signed integer
  • Trailing whitespace and a trailing newline are ignored by the judge

Read from stdin, write to stdout. Sample cases below show the exact format.

Sample cases

Example 1
Input
7 2
1 1 2 2 2 3 3
Expected output
3
Example 2
Input
3 5
1 2 3
Expected output
0