#include <stdio.h>
// Function to return Lower Bound
int lowerBound(int arr[], int n, int target) {
int res = n;
// Search space for binary search
int lo = 0, hi = n - 1;
while (lo <= hi) {
int mid = lo + (hi - lo) / 2;
if (arr[mid] >= target) {
res = mid;
hi = mid - 1;
} else {
lo = mid + 1;
}
}
return res;
}
// Function to return Upper Bound
int upperBound(int arr[], int n, int target) {
int res = n;
// Search space for binary search
int lo = 0, hi = n - 1;
while (lo <= hi) {
int mid = lo + (hi - lo) / 2;
if (arr[mid] > target) {
res = mid;
hi = mid - 1;
} else {
lo = mid + 1;
}
}
return res;
}
int countFreq(int arr[], int n, int target) {
// Return the difference between upper
// bound and lower bound of the target
return upperBound(arr, n, target) -
lowerBound(arr, n, target);
}
int main() {
int arr[] = {1, 2, 2, 2, 2, 3, 4, 7, 8, 8};
int target = 2;
int n = sizeof(arr) / sizeof(arr[0]);
printf("%d\n", countFreq(arr, n, target));
return 0;
}