atcoder#AGC015E. [AGC015E] Mr.Aoki Incubator

[AGC015E] Mr.Aoki Incubator

Score : 12001200 points

Problem Statement

Takahashi is an expert of Clone Jutsu, a secret art that creates copies of his body.

On a number line, there are NN copies of Takahashi, numbered 11 through NN. The ii-th copy is located at position XiX_i and starts walking with velocity ViV_i in the positive direction at time 00.

Kenus is a master of Transformation Jutsu, and not only can he change into a person other than himself, but he can also transform another person into someone else.

Kenus can select some of the copies of Takahashi at time 00, and transform them into copies of Aoki, another Ninja. The walking velocity of a copy does not change when it transforms. From then on, whenever a copy of Takahashi and a copy of Aoki are at the same coordinate, that copy of Takahashi transforms into a copy of Aoki.

Among the 2N2^N ways to transform some copies of Takahashi into copies of Aoki at time 00, in how many ways will all the copies of Takahashi become copies of Aoki after a sufficiently long time? Find the count modulo 109+710^9+7.

Constraints

  • 1N2000001 \leq N \leq 200000
  • 1Xi,Vi109(1iN)1 \leq X_i,V_i \leq 10^9(1 \leq i \leq N)
  • XiX_i and ViV_i are integers.
  • All XiX_i are distinct.
  • All ViV_i are distinct.

Input

The input is given from Standard Input in the following format:

NN

X1X_1 V1V_1

:

XNX_N VNV_N

Output

Print the number of the ways that cause all the copies of Takahashi to turn into copies of Aoki after a sufficiently long time, modulo 109+710^9+7.

3
2 5
6 1
3 7
6

All copies of Takahashi will turn into copies of Aoki after a sufficiently long time if Kenus transforms one of the following sets of copies of Takahashi into copies of Aoki: (2)(2), (3)(3), (1,2)(1,2), (1,3)(1,3), (2,3)(2,3) and (1,2,3)(1,2,3).

4
3 7
2 9
8 16
10 8
9