SPOJ 1724: Counting Triangles