#P11048. The Cross Puzzle

    ID: 13102 Type: Default 1000ms 256MiB

The Cross Puzzle

The Cross Puzzle

In the mysterious ancient forest of LQ, there lies a legendary relic called the "Cross Puzzle". It is said that the relic, built by an ancient civilization, consists of two large overlapping rectangles arranged in a cross formation. According to the legend, the relic serves as a bridge between humans and the divine, and it exudes a mysterious power and energy.

You are given N rectangles. For the i-th rectangle, its length and width are given by \(l_i\) and \(w_i\) respectively, and its color \(c_i\) is one of the following: red (0), yellow (1), or blue (2). The rectangles' dimensions are fixed (i.e. they cannot be rotated).

The task is to count how many ordered pairs of rectangles \((i, j)\) can form a cross. Two rectangles \(i\) and \(j\) can form a cross if and only if they satisfy the following conditions:

  1. The two rectangles have different colors.
  2. \(l_i > l_j\) and \(w_i < w_j\); that is, the first rectangle has a strictly greater length and a strictly smaller width than the second rectangle.

Output the total number of such ordered pairs.

inputFormat

The first line contains a single integer \(N\) (the number of rectangles).
Each of the following \(N\) lines contains three integers \(l_i\), \(w_i\), and \(c_i\), where \(l_i\) and \(w_i\) represent the length and width of the \(i\)-th rectangle, and \(c_i\) represents its color (0 for red, 1 for yellow, and 2 for blue).

outputFormat

Output a single integer, the total number of ordered pairs of rectangles that can form a cross according to the given conditions.

sample

3
3 4 0
2 5 1
1 6 2
3