Score : 900 points
Problem Statement
Given are an integer N and M pairs of integers.
The i-th pair is (Li,Ri).
Find the number of integer sequences x=(x1,x2,⋯,xM) that can be generated as follows, modulo 998244353.
- Provide a permutation p=(p1,p2,⋯,pN) of (1,2,⋯,N).
- For each i (1≤i≤M), let xi be the index of the largest element among pLi,pLi+1,⋯,pRi. That is, max(pLi,pLi+1,⋯,pRi)=pxi.
Constraints
- 2≤N≤300
- 1≤M≤N(N−1)/2
- 1≤Li<Ri≤N
- (Li,Ri)=(Lj,Rj) (i=j)
- All values in input are integers.
Input is given from Standard Input in the following format:
N M
L1 R1
L2 R2
⋮
LM RM
Output
Print the answer.
3 2
1 2
1 3
4
For example, for p=(2,1,3), we will have x=(1,3).
The four sequences that meet the requirement are x=(1,1),(1,3),(2,2),(2,3).
6 3
1 2
3 4
5 6
8
10 10
8 10
5 8
5 7
2 5
1 7
4 5
5 9
2 8
7 8
3 9
1060