P18130 [ICPC 2026 Seoul R] Summoning Triangle

Description

In the kingdom of ICPC, $n$ magic stones are scattered across the land. Each magic stone is located at a point on a plane and possesses exactly one of the $k$ different elements. No three magic stones are collinear. To defeat the evil “Demon Lord,” the kingdom must summon heroes from another world using summoning triangles. A summoning triangle is a triangle whose three vertices are magic stones. For a successful summoning, the triangle must contain exactly one magic stone of each of the $k$ elements, counting the stones at its vertices and in its interior. Since no three magic stones are collinear, no other stone can lie on an edge of the triangle. Given the positions and elements of $n$ magic stones, count the number of summoning triangles that can successfully summon a hero.

Input Format

Your program is to read from standard input. The input starts with a line containing two integers, $n$ and $k$ ($3 \le n \le 300$, $3 \le k \le n$), where $n$ is the number of magic stones and $k$ is the number of elements. Each of the next $n$ lines contains three integers $x$, $y$ ($0 \le x,y \le 50{,}000$), and $z$ ($1 \le z \le k$) that represent the coordinates $(x,y)$ and element $z$ of a magic stone. It is guaranteed that all magic stones are located at distinct points, no three magic stones are collinear, and at least one magic stone of each element is present.

Output Format

Your program is to write to standard output. Print exactly one line. The line should contain the number of summoning triangles that can successfully summon a hero.