Under construction

Still being built. Things may change

Constellation 2

Time limit9sMemory limit512 MB

Summary
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 Pi(Xi,Yi)P_i(X_i, Y_i) on the coordinate plane. The points P1,…,PNP_1, \ldots, P_N 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 XiX_i, YiY_i, and CiC_i, separated by spaces. Star i is at Pi(Xi,Yi)P_i(X_i, Y_i). If CiC_i is 0, star i is red. If CiC_i is 1, it is blue. If CiC_i is 2, it is yellow.

Output

Print to standard output the total number of JOIOI candidates as a single integer on one line.

Constraints

  • 6≤N≤30006 \le N \le 3000.
  • −100000≤Xi≤100000-100000 \le X_i \le 100000.
  • −100000≤Yi≤100000-100000 \le Y_i \le 100000.
  • 0≤Ci≤20 \le C_i \le 2.
  • There is at least one star of each color.
  • Pi≠PjP_i \ne P_j (1≤i<j≤N1 \le i < j \le N).
  • No three points Pi,Pj,PkP_i, P_j, P_k lie on the same line (1≤i<j<k≤N1 \le i < j < k \le N).

Examples3

  1. Example 1

    Input
    7
    0 0 0
    2 0 1
    1 2 2
    -2 1 0
    -2 -3 0
    0 -2 1
    2 -2 2
    
    Expected output
    4
    
  2. Example 2

    Input
    8
    16 0 0
    17 0 0
    0 7 2
    0 -7 2
    -1 -1 1
    -1 1 2
    -6 4 1
    -6 -4 1
    
    Expected output
    12
    
  3. Example 3

    Input
    21
    1 20 0
    4 20 0
    0 22 0
    5 22 0
    6 25 0
    8 25 0
    4 26 0
    11 11 1
    7 12 1
    14 13 1
    8 15 1
    15 16 1
    11 17 1
    18 0 2
    13 2 2
    16 2 2
    19 4 2
    18 6 2
    21 8 2
    24 8 2
    19 10 2
    
    Expected output
    7748