Count the occurrences of a number in a sorted array.