how to count the occurrences of a number