#P5464. 缩小社交圈

缩小社交圈

Problem Description

There are nn people in a social circle. Each person has a SAN value interval [li,ri][l_i, r_i]. If the SAN intervals of two people have a non-empty intersection, then these two people have a PY relationship.

Now we want to pick some people from the social circle to form a set SS. If we add an edge between every pair of people in the set who have a PY relationship, then SS must form exactly a tree (a forest is not allowed).

How many ways are there to choose such a set? Since the answer may be very large, output it modulo 109+710^{9}+7.

Input Format

The first line contains an integer nn.

The next nn lines each contain two integers, describing the SAN value interval of a person.

Output Format

Output one integer, the answer.

3
1 5
2 7
4 8

6

Hint

For 20%20\% of the testdata, n18n \leq 18.

For 40%40\% of the testdata, n50n \leq 50.

For 60%60\% of the testdata, n200n \leq 200.

For 100%100\% of the testdata, n2000n \leq 2000, 1li<ri40001 \leq l_i < r_i \leq 4000.

Translated by ChatGPT 5