Count the rectangles and squares in a grid by choosing the lines that make them, instead of trying to spot them all.