~/algor $ cat problems/kombinatorika-tosiqli-maydon
Large field with obstacles
Hard
2000 ms
128 MB
95%
On a grid of $n$ rows and $m$ columns, $k$ cells are occupied by obstacles. In how many ways can one get from the top-left cell $(1; 1)$ to the bottom-right cell $(n; m)$, moving only right or down and never stepping on an obstacle? Print the answer modulo $10^{9} + 7$.
Input
The first line contains three integers: $n$, $m$ and $k$. Each of the next $k$ lines contains two positive integers: the row $r_{i}$ and the column $c_{i}$ of an obstacle cell.
Output
One integer — the number of paths modulo $10^{9} + 7$.
Note
$1 \le n, m \le 10^{5}$
$0 \le k \le 1000$
the obstacles are in different cells, cells $(1; 1)$ and $(n; m)$ are free
Examples
Input #1
3 4 2 2 2 2 3
Output #1
2
Input #2
2 2 1 1 2
Output #2
1