Why the Fox Climbed Information Island
InterviewTime limit1sMemory limit256 MB
Count triples of stars (s,t,u) with s.x < t.x < u.x and s.y > t.y < u.y, output the count modulo 1e9+7.
- Level
Medium6 of 10
- Topics
- Sorting, Binary search, Prefix sum, Combinatorics
- Solved
- No attempts yet
Problem
A fox has climbed Information Island!
The sky is full of beautiful stars shining again today. Information Island sits on top of a hill, so it is famous for its clear view of the stars. Perhaps that is why a fox has come up to Information Island and is gazing at the night sky, making constellations. The fox connects three stars to make a V-shaped constellation, supposedly because a V looks like its face. Since the fox thinks from its own viewpoint, it does not consider rotated forms of a V (<, >, L, Γ, ^, and so on) to be V shapes.
The fox became curious about the total number of V-shaped constellations it can make. Counting them one by one would take too long because there are so many stars, so the fox asked you, an excellent programmer, for help! For the sake of the cute fox, let us compute how many V-shaped constellations can be made.
A V-shaped constellation is defined precisely as follows. Three stars form a V-shaped constellation if and . For example, in the 'Information Island night sky reference diagram' below, forms a V-shaped constellation, but does not, because does not hold. When counting V-shaped constellations, a single star may belong to multiple constellations.

The answer can become very large, so output the remainder when it is divided by .
Input
The first line gives the number of stars, . The following lines each give the coordinates of a star.
Output
Output (the number of V-shaped constellations that can be made) mod .
Constraints
- ( are integers)