Rewrite countc function in tally.lua