Constellation 2
Time limit9sMemory limit512 MB
Count unordered pairs of non-overlapping triangles, each with one red, one blue, and one yellow star, among N colored points.
- Level
Hard8 of 10
- Topics
- Geometry, Sorting, Implementation
- Solved
- No attempts yet
Problem
JOI and IOI are best friends. One day they decided to observe the sky from an observatory on a mountain.
The observatory can observe N stars. The stars are numbered 1 to N, and each star is red, blue, or yellow.
Star i is the point on the coordinate plane. The points are all distinct, and no three of them lie on the same line.
JOI and IOI want to make a constellation called JOIOI. First, they consider a triangle whose three vertices are one red star, one blue star, and one yellow star. Such a triangle is called a good triangle. They define a JOIOI candidate as an unordered pair of two good triangles that satisfies the following condition.
- The two good triangles, including their edges and interiors, have no common point. In other words, the triangles cannot overlap, and one cannot contain the other.

An example that satisfies the condition.

An example that does not satisfy the condition.
JOI and IOI want to count how many JOIOI candidates there are. If two candidates use the same six stars but form the good triangles in different ways, they are counted as different candidates.
Given the observed stars, print the total number of JOIOI candidates.
Input
Read the following data from standard input.
The first line contains an integer N, the number of stars. Each of the next N lines contains three integers , , and , separated by spaces. Star i is at . If is 0, star i is red. If is 1, it is blue. If is 2, it is yellow.
Output
Print to standard output the total number of JOIOI candidates as a single integer on one line.
Constraints
- .
- .
- .
- .
- There is at least one star of each color.
- ().
- No three points lie on the same line ().