시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 1024 MB58403271.111%

문제

To commemorate the end of a memorable era, the city is holding a Last Celebration. As a grand finale, a group of $N$ artists has been commissioned to create a final, collaborative mural on a massive city wall. The wall has a length of $D$ and is divided into $D$ sections, numbered from $1$ to $D$. Before they begin, the entire wall is primed with a base color, represented as color $0$.

Each artist $i$ is assigned a specific task: to paint the sections from $l_i$ to $r_i$ with their designated color $c_i$. As the artists work, some sections might be painted over multiple times. The final color of any section is determined by the last artist to paint it.

The quality of the final artwork is determined by its diversity. A block is defined as a maximal contiguous segment of the wall painted in a single color. The diversity of the wall is the total number of blocks.

The $N$ artists will complete their tasks in a random order. Each of the $N!$ possible permutations is equally likely. Your goal is to calculate the expected value of the wall's diversity after all artists are finished.

입력

The first line contains two integers, $D$ and $N$ — the length of the wall and the number of artists.

The following $N$ lines each contain three integers, $l_i$, $r_i$, and $c_i$ — the range and color for the $i$-th artist.

출력

Output the expected value of the wall's diversity. Since the expectation can be rational, output it modulo $998\,244\,353$. Formally, if the expectation equals $s/t$ in lowest terms, print $s\times t^{-1}\pmod{998\,244\,353}$, where $t^{-1}$ is the modular inverse of $t$ modulo $998\,244\,353$.

제한

  • $1 \le D \le 10^9$
  • $1 \le N \le 2 \cdot 10^5$
  • $1 \le l_i \le r_i \le D$
  • $1 \le c_i \le N$

예제 입력 1

5 2
1 4 1
2 3 2

예제 출력 1

3

예제 입력 2

6 3
2 3 1
4 5 1
1 6 2

예제 출력 2

332748120

예제 입력 3

1000000000 9
1 2 1
11 22 1
111 222 1
1111 2222 1
11111 22222 1
111111 222222 1
1111111 2222222 1
11111111 22222222 1
111111111 222222222 1

예제 출력 3

18

예제 입력 4

4 10
1 1 1
1 2 2
1 3 3
1 4 4
2 2 5
2 3 6
2 4 7
3 3 8
3 4 9
4 4 10

예제 출력 4

356515843