How would you apply a hashing algorithm to solve a particular problem? Implement count_pairs(nums, target) to return the number of index pairs i < j whose values sum to target, counting duplicate values at different indices as separate pairs. The input is an integer list and an integer target, and the output is a nonnegative integer; use a hash-based approach rather than enumerating every pair.
def count_pairs(nums, target):