Mooball Teams III

시간 제한2초메모리 제한1024 MB

요약
소들을 가로 또는 세로의 비정수 좌표 직선 하나로 나눌 수 있을 때, 서로소인 비어 있지 않은 두 팀을 고르는 경우의 수를 센다.
난이도

어려움10점 중 8점

유형
누적 합, 정렬, 조합론, 수학
정답자
아직 제출이 없습니다

문제

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

One of the teams will be the "red" team; the other team will be the "blue" team. There are only a few requirements for the teams. Neither team can be empty, and each of the NN cows must be on at most one team (possibly neither). The only other requirement is due to a unique feature of mooball: an infinitely long net, which must be placed as either a horizontal or vertical line in the plane at a non-integer coordinate, such as x=0.5x = 0.5. FJ must pick teams so that it is possible to separate the teams by a net. The cows are unwilling to move to make this true.

Help a farmer out! Compute for Farmer John the number of ways to pick a red team and a blue team satisfying the above requirements, modulo 109+710^9+7.

입력

The first line of input contains a single integer N.N.

The next NN lines of input each contain two space-separated integers x_ix\_i and y_iy\_i. It is guaranteed that the x_ix\_i form a permutation of 1…N1\dots N, and same for the y_iy\_i.

출력

A single integer denoting the number of ways to pick a red team and a blue team satisfying the above requirements, modulo 109+710^9+7.

예제4

  1. 예제 1

    입력
    2
    1 2
    2 1
    
    예상 출력
    2
    
  2. 예제 2

    입력
    3
    1 1
    2 2
    3 3
    
    예상 출력
    10
    
  3. 예제 3

    입력
    3
    1 1
    2 3
    3 2
    
    예상 출력
    12
    
  4. 예제 4

    입력
    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
    
    예상 출력
    441563023