close #19 : count territories algorithm