Fixed algorithm of counting of number occurrences in sorted array.