Solution works with binary triangles