#P9221. 「TAOI-1」Pentiment
「TAOI-1」Pentiment
Background
Recently (dubious), a game called 闊靛緥婧愮偣 updated to version 4.0. In this version, a certain chart’s huge right-angle snake left a deep impression on the players...

Problem Description
We define the following in an -row, -column grid: a “right-angle snake” is a path with these rules:
- It starts from the center of some cell in the bottommost row (row ) and ends at the center of some cell in the topmost row (row ).
- Each move can go up, right, or left by one cell, and after each move it arrives at the center of a cell (moving down is not allowed).
- It cannot pass through the same cell more than once.
In particular, to make it more challenging, some cells are forbidden for the “right-angle snake” to pass through.
Count how many such “right-angle snakes” exist in the given grid. Output the answer modulo .
Input Format
The first line contains three integers , representing the number of rows, the number of columns, and the number of constraints.
The next lines each contain two integers , meaning that the cell at row and column cannot be passed through. It is guaranteed that each cell appears at most once. It is guaranteed that all cells are given in increasing order when sorted by as the primary key and as the secondary key. (We define the bottommost row as row , and the leftmost column as column .)
Output Format
Output one integer: the number of valid “right-angle snakes” modulo .
2 3 2
1 1
2 1
8
4 4 4
1 1
2 2
3 3
4 4
0
6 5 4
1 3
3 1
3 4
5 2
2000
100000000 100000000 0
103866487
Hint
Constraints
This problem uses bundled testdata.
- Subtask 1 (10 points): , .
- Subtask 2 (10 points): .
- Subtask 3 (15 points): .
- Subtask 4 (20 points): .
- Subtask 5 (20 points): .
- Subtask 6 (25 points): no special restrictions.
For all testdata, , , , , .
Sample Explanation

As shown in the figure, there are eight valid “right-angle snakes” in Sample 1.
For Sample 2, there are no valid “right-angle snakes”.
Surrender in ashes as cold as death.
Surrender amid drifting uncertainty.
Surrender at the last step, just short of success.
Translated by ChatGPT 5