Under construction

Still being built. Things may change

Kraniki

Time limit4sMemory limit1024 MB

Summary
Given n shelves at heights 1 to n, each with endpoints l_i and r_i, find the expected number of taps opened over a random order, modulo 1e9+7.
Level

Medium7 of 10

Topics
Intervals, Stack, Probability
Solved
No attempts yet

Statement

Radek, the boss of the firm Radek and Friends, wants to flood every document shelf at the rival company Mati and Partners. For a perfect sabotage, he asked his friend, the plumber Janusz, to install small water taps above each shelf.

The shelves are segments in the plane. Shelf ii is the segment between points (li,hi)(l_i, h_i) and (ri,hi)(r_i, h_i). The tap above shelf ii is placed at (li+ri2,hi+0.5)\left(\frac{l_i + r_i}{2}, h_i + 0.5\right). The floor is the OXOX axis.

When the tap above shelf ii is opened, that shelf is flooded. Water then drips straight down from the ends of the flooded shelves. It may flood shelves below, or drip onto the floor, which has a natural drainage system.

Radek considers the taps in a fixed order. When he considers tap ii, he opens it only if shelf ii is not flooded yet.

Radek has not chosen the order yet. He picks one of the n!n! orders uniformly at random. Find the expected number of taps Radek has to open.

Input

The first line contains one natural number nn (1≤n≤500 0001 \le n \le 500\,000), the number of shelves at Mati and Partners.

Each of the next nn lines describes one shelf. Line ii contains two natural numbers lil_i and rir_i (1≤li<ri≤2⋅n1 \le l_i < r_i \le 2 \cdot n). Here hi=ih_i = i.

All numbers lil_i and rir_i are pairwise distinct. Together they form a permutation of 11 to 2⋅n2 \cdot n.

Output

Print one number: the expected number of taps Radek has to open, modulo 109+710^9 + 7. Formally, let the answer be p/qp/q with q≠0q \ne 0 and gcd⁡(p,q)=1\gcd(p, q) = 1. Print p⋅q−1(mod109+7)p \cdot q^{-1} \pmod{10^9 + 7}, where q−1q^{-1} is the unique integer from 11 to 109+610^9 + 6 such that q⋅q−1≡1(mod109+7)q \cdot q^{-1} \equiv 1 \pmod{10^9 + 7}. The denominator of the reduced answer is proven not to be divisible by 109+710^9 + 7.

Hint

In the first test, the average is 16⋅(3+2+3+2+1+1)=2\frac{1}{6} \cdot (3 + 2 + 3 + 2 + 1 + 1) = 2. For order 1, 3, 2, Radek opens taps 1 and 3. After tap 3 is opened, shelf 2 is also flooded, so he skips tap 2. For orders 3, 1, 2 and 3, 2, 1, opening tap 3 floods every shelf, so no other tap is opened.

Examples2

  1. Example 1

    Input
    3
    4 6
    1 3
    2 5
    
    Expected output
    2
    
  2. Example 2

    Input
    5
    2 9
    3 4
    1 8
    6 10
    5 7
    
    Expected output
    233333338