Counting Algorithm Pseudocode