PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#PS0000266. Bước nhảy của Tak (Leaping Tak)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Bước nhảy của Tak (Leaping Tak)

Leaping Tak

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

There are NN cells numbered 1 through NN. Tak starts at cell 1. Given KK pairwise disjoint inclusive integer intervals [Li,Ri][L_i,R_i], each move chooses an integer dd in their union and advances from xx to x+dx+d without passing NN. Count the sequences of moves reaching NN, modulo 998244353998244353.

Input

First line: N,KN,K. Next KK lines: Li,RiL_i,R_i.

Output

Print the number of ways modulo 998244353998244353.

Subtasks

  • Subtask 1 (20 points): 2≤N≤1002\le N\le 100; 1≤K≤min⁡(N,10)1\le K\le\min(N,10); 1≤Li≤Ri≤N1\le L_i\le R_i\le N; pairwise disjoint intervals.
  • Subtask 2 (30 points): 2≤N≤2000002\le N\le 200000; 1≤K≤min⁡(N,10)1\le K\le\min(N,10); 1≤Li≤Ri≤N1\le L_i\le R_i\le N; pairwise disjoint intervals; K=1K=1.
  • Subtask 3 (50 points): 2≤N≤2000002\le N\le 200000; 1≤K≤min⁡(N,10)1\le K\le\min(N,10); 1≤Li≤Ri≤N1\le L_i\le R_i\le N; pairwise disjoint intervals.

Example 1

Input

5 2
1 1
3 4

Output

4

Explanation

The move sequences are (1,1,1,1), (1,3), (3,1), (4).

Example 2

Input

5 2
3 3
5 5

Output

0

Explanation

Neither 3 nor 5 can form a total of 4.

Example 3

Input

5 1
1 2

Output

5

Explanation

The five compositions of 4 use parts 1 and 2.

Example 4

Input

60 3
5 8
1 3
10 15

Output

221823067

Explanation

Count move sequences totaling 59 and reduce modulo 998244353.