atcoder#ABC273H. [ABC273Ex] Inv(0,1)ving Insert(1,0)n
[ABC273Ex] Inv(0,1)ving Insert(1,0)n
Score : points
Problem Statement
We have a sequence consisting of integer pairs. Initially, .
You may perform the following operation on as many (possibly zero) times as you want:
- choose adjacent two integer pairs and , and insert between them.
For a sequence consisting of integer pairs, let us define as follows:
- let (the minimum number of operations required to make every element of contained in ).- We say that "every element of is contained in " if, for all elements contained in , is contained in (the set consisting of the elements contained in ).
- We say that "every element of is contained in " if, for all elements contained in , is contained in (the set consisting of the elements contained in ).
- Here, if there are no such operations, let .
There is a sequence consisting of integer pairs. Here, all elements of are pairwise distinct. There are possible consecutive subarrays $S_{l,r}=((a_l,b_l),(a_{l+1},b_{l+1}),\dots,(a_r,b_r))$ of . Find the sum, modulo , of over those subarrays. Formally, find $\displaystyle \sum^{N} _ {l=1} \sum^{N} _ {r=l} f(S_{l,r})$, modulo .
Constraints
- or , if .
Input
The input is given from Standard Input in the following format:
Output
Print the answer as an integer.
7
1 2
3 7
3 5
0 0
1000000000 1
0 1
6 3
3511324
- .- We can make $((0,1),(1,0)) \rightarrow ((0,1),(1,1),(1,0)) \rightarrow ((0,1),(1,2),(1,1),(1,0))$.
- We can make $((0,1),(1,0)) \rightarrow ((0,1),(1,1),(1,0)) \rightarrow ((0,1),(1,2),(1,1),(1,0))$.
- .
- .
- .
- .
- .
- .
- .
- .- is originally contained in .
- is originally contained in .
- for all not mentioned above.- We can prove that can never contain or regardless of operations.
- We can prove that can never contain or regardless of operations.
Therefore, the sum of is , whose remainder when divided by is .