public class FineNumber53 {
public static void main(String[] args) {
int[] arr = {1, 2, 3, 3, 3, 4, 5};
int n = 3;
int first = times(arr, n);
int last = times(arr, n + 1);
int times = (first == arr.length || arr[first] != n) ? 0 : last - first;
System.out.println(times);
}
private static int times(int[] arr, int n) {
int low = 0, high = arr.length - 1;
while (low < high) {
int mid = low + (high - low) / 2;
if (arr[mid] >= n) {
high = mid;
} else {
low = mid + 1;
}
}
return low;
}
}