the solution of the CountTriangles