Homework exercises solving N+1 problem