Removed memoization from PatternCounter for simplicity.