Code Submission Evaluation System Login

CSES Problem Set

Grid Paths

Task | Statistics

CSES - Grid PathsCSES - Grid Paths

Time limit:1.00 s Memory limit:512 MB

Consider an $n \times n$ grid whose top-left square is $(1,1)$ and bottom-right square is $(n,n)$.

Your task is to move from the top-left square to the bottom-right square. On each step you may move one square right or down. In addition, there are $m$ traps in the grid. You cannot move to a square which has a trap.

What is the total number of possible paths?


The first input line contains two integers $n$ and $m$: the size of the grid and the number of traps.

After this, there are $m$ lines that describe the traps. Each such line contains two integers $y$ and $x$: the location of a trap.

You can assume that there are no traps in the top-left and bottom-right square.


Print the number of paths modulo $10^9+7$.


3 1
2 2