Counting techniques I: Combinatorics and algebraic geometry