This page is still under construction.

Parts of this page are still being built. What you see may change.

Why the Fox Climbed Information Island

Interview

Time limit1sMemory limit256 MB

Summary
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 (s,t,u)(s,t,u) form a V-shaped constellation if s.x<t.x<u.xs.x < t.x < u.x and s.y>t.y<u.ys.y > t.y < u.y. For example, in the 'Information Island night sky reference diagram' below, (a,b,c)(a,b,c) forms a V-shaped constellation, but (d,b,c)(d,b,c) does not, because d.x<b.xd.x < b.x 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 (109+7)(10^9+7).

Input

The first line gives the number of stars, NN. The following NN lines each give the coordinates xx yy of a star.

Output

Output (the number of V-shaped constellations that can be made) mod (109+7)(10^9+7).

Constraints

  • 1≤N≤2×1051 \le N \le 2\times 10^5
  • −2×105≤x,y≤2×105-2\times 10^5 \le x,y \le 2\times 10^5 (x,yx,y are integers)

Examples2

  1. Example 1

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

    Input
    10
    -2 0
    -1 0
    0 0
    1 0
    2 0
    -2 1
    -1 1
    0 1
    1 1
    2 1
    
    Expected output
    10