Under construction

Still being built. Things may change

Eggplant Field Path

Time limit1sMemory limit1024 MB

Summary
Count the distinct ways a monotone lattice path from (0,0) to (R,C) can split the planted branches into upper and lower sets without touching any branch.
Level

Hard8 of 10

Topics
Dynamic programming, Combinatorics, Math
Solved
No attempts yet

Problem

The eggplant field is a rectangular grid with RR rows and CC columns. Two lattice points at distance 11 are joined by a segment-shaped path. Every morning, Bamgo leaves for work from the top left point (0,0)(0, 0) and walks to the bottom right point (R,C)(R, C) using exactly R+CR+C segments. Some lattice points have cute branches planted on them, so Bamgo cannot pass through those points.

Bamgo has walked this field every day and believes that some routes across it are effectively the same. When the route Bamgo walked cuts the grid into two regions, some points lie in the upper region and the rest lie in the lower region. Two routes are the same if every branch falls in the same region, upper or lower, under both routes. How many distinct routes does Bamgo think there are?

See the note for the exact definition of the two cut regions.

Input

The first line contains three integers RR, CC, and KK, separated by spaces. RR and CC are the height and width of the rectangular grid, and KK is the number of planted branches. (1≤R,C,K≤5 000)(1 \le R, C, K \le 5\,000)

Each of the next KK lines contains two integers rr and cc, separated by a space, giving the position (r,c)(r, c) of a planted branch. (0≤r≤R  ;0≤c≤C)(0 \le r \le R\;; 0 \le c \le C)

All branch coordinates are distinct, and there are no branches at (0,0)(0, 0) or (R,C)(R, C).

Output

On the first line, print the number of distinct routes according to Bamgo, modulo the prime 1 000 000 007=109+71\,000\,000\,007 = 10^9+7.

Hints

The exact definition of the two regions is as follows.

  • If the route Bamgo walked passes through (R,0)(R, 0), the upper region is the whole set and the lower region is the empty set.
  • Otherwise, if the route passes through (0,C)(0, C), the lower region is the whole set and the upper region is the empty set.
  • In all other cases, the region containing (R,0)(R, 0) is called the lower region, and the region containing (0,C)(0, C) is called the upper region.

Examples4

  1. Example 1

    Input
    4 4 3
    1 1
    1 3
    3 1
    
    Expected output
    4
    
  2. Example 2

    Input
    4 4 4
    1 1
    1 3
    3 1
    3 3
    
    Expected output
    6
    
  3. Example 3

    Input
    10 10 5
    1 1
    3 3
    5 5
    7 7
    9 9
    
    Expected output
    32
    
  4. Example 4

    Input
    10 10 5
    1 9
    3 7
    5 5
    7 3
    9 1
    
    Expected output
    6