Under construction

Still being built. Things may change

Chessboard

Time limit2sMemory limit512 MB

Summary
Count the pairs of non-meeting lattice paths from (1,1) to (N,M) on a board with K forbidden cells, where the first moves are fixed, modulo 1e9+7.
Level

Hard8 of 10

Topics
Combinatorics, Dynamic programming, Math
Solved
No attempts yet

Problem

A chessboard has N×MN \times M cells. Rows are numbered 1,2,⋯ ,N1, 2, \cdots, N from top to bottom, and columns are numbered 1,2,⋯ ,M1, 2, \cdots, M from left to right. Cell (i,j)(i, j) is in row ii and column jj. The board has KK forbidden cells. Neither (1,1)(1,1) nor (N,M)(N,M) is forbidden.

Pieces AA and BB start at (1,1)(1,1) and move together, one cell at a time, toward (N,M)(N,M) under these rules.

  1. A piece at (i,j)(i,j) can move to (i+1,j)(i+1,j) or (i,j+1)(i,j+1). A move that leaves the board is not allowed.
  2. At the start, piece AA moves from (1,1)(1,1) to (1,2)(1,2), and piece BB moves from (1,1)(1,1) to (2,1)(2,1).
  3. While moving, the two pieces must not meet on any cell except (1,1)(1,1) and (N,M)(N,M).
  4. Neither piece can move onto a forbidden cell.

Following these rules, count the pairs of paths (a,b)(a,b) that take pieces AA and BB from (1,1)(1,1) to (N,M)(N,M), where aa is the path of piece AA and bb is the path of piece BB.

Input

The first line contains NN, MM, and KK, separated by spaces. (2≤N,M≤1 000 0002 \le N,M \le 1\,000\,000, 0≤K≤min⁡(N×M−2,5 000)0 \le K \le \min(N \times M-2,5\,000))

Each of the next KK lines contains the row number xx and column number yy of a forbidden cell, separated by a space. No cell is given twice. (1≤x≤N1 \le x \le N, 1≤y≤M1 \le y \le M, (x,y)≠(1,1)(x,y) \neq (1,1), (x,y)≠(N,M)(x,y) \neq (N,M))

All numbers in the input are integers.

Output

Print the number of path pairs that let pieces AA and BB start together at (1,1)(1,1) and reach (N,M)(N,M), modulo 109+710^9 + 7.

Examples2

  1. Example 1

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

    Input
    5 5 4
    3 1
    3 5
    1 3
    5 3
    
    Expected output
    0