Under construction

Still being built. Things may change

Mooball Teams III

Time limit2sMemory limit1024 MB

Summary
Count pairs of nonempty, disjoint red and blue cow sets that one horizontal or vertical net at a half-integer coordinate separates, modulo 1e9+7.
Level

Medium7 of 10

Topics
Combinatorics, Math, Implementation
Solved
No attempts yet

Problem

Farmer John has NN cows on his farm (2≤N≤2⋅1052 \leq N \leq 2\cdot 10^5), numbered 1…N1 \dots N. Cow ii is located at integer coordinates (xi,yi)(x_i, y_i) (1≤xi,yi≤N1\le x_i,y_i\le N). Farmer John wants to pick two teams for a game of mooball.

One team is the "red" team and the other is the "blue" team. Neither team can be empty, and each cow may be on at most one team (or on neither). Mooball has one more rule. An infinitely long net must be placed as either a horizontal or vertical line at a non-integer coordinate, such as x=0.5x = 0.5, and the two teams must be separated by that net. The cows will not move to make this true.

Count the ways to pick a red team and a blue team that satisfy these conditions, modulo 109+710^9+7.

Input

The first line contains a single integer NN.

Each of the next NN lines contains two space-separated integers xix_i and yiy_i. The xix_i form a permutation of 1…N1 \dots N, and the yiy_i form a permutation of 1…N1 \dots N.

Output

Print a single integer: the number of ways to pick a red team and a blue team that satisfy the conditions, modulo 109+710^9+7.

Examples4

  1. Example 1

    Input
    2
    1 2
    2 1
    
    Expected output
    2
    
  2. Example 2

    Input
    3
    1 1
    2 2
    3 3
    
    Expected output
    10
    
  3. Example 3

    Input
    3
    1 1
    2 3
    3 2
    
    Expected output
    12
    
  4. Example 4

    Input
    40
    1 1
    2 2
    3 3
    4 4
    5 5
    6 6
    7 7
    8 8
    9 9
    10 10
    11 11
    12 12
    13 13
    14 14
    15 15
    16 16
    17 17
    18 18
    19 19
    20 20
    21 21
    22 22
    23 23
    24 24
    25 25
    26 26
    27 27
    28 28
    29 29
    30 30
    31 31
    32 32
    33 33
    34 34
    35 35
    36 36
    37 37
    38 38
    39 39
    40 40
    
    Expected output
    441563023