Under construction

Still being built. Things may change

Commute Route

Interview

Time limit1sMemory limit128 MB

Summary
Count monotone east/north lattice paths from (1,1) to (a,b) that avoid n blocked intersections, with a and b at most 16.
Level

Easy3 of 10

Topics
Dynamic programming, Combinatorics, Array, Matrix
Solved
No attempts yet

Problem

Taro lives in JOI City, which is divided into a grid by aa roads running straight in the north–south direction and bb roads running straight in the east–west direction.

The aa north–south roads are numbered 1,2,…,a1, 2, \dots, a from west to east. The bb east–west roads are numbered 1,2,…,b1, 2, \dots, b from south to north. The intersection where the ii-th north–south road (from the west) meets the jj-th east–west road (from the south) is denoted (i,j)(i, j).

Taro lives near intersection (1,1)(1, 1) and commutes by bicycle to JOI High School, which is near intersection (a,b)(a, b). The bicycle can move only along the roads. To shorten his commute, Taro always moves only toward the east or the north.

Currently, construction is underway at nn intersections (x1,y1),(x2,y2),…,(xn,yn)(x_1, y_1), (x_2, y_2), \dots, (x_n, y_n), and Taro cannot pass through an intersection that is under construction.

How many ways can Taro commute from intersection (1,1)(1, 1) to intersection (a,b)(a, b), moving only east or north while avoiding every intersection under construction? Write a program that computes the number of commute routes mm.

Input

The first line contains two integers aa and bb, separated by a space, giving the number of north–south roads and the number of east–west roads, respectively. They satisfy 1≤a,b≤161 \le a, b \le 16.

The second line contains an integer nn, the number of intersections under construction, satisfying 1≤n≤401 \le n \le 40.

Each of the following nn lines gives the position of an intersection under construction: the ii-th such line contains two space-separated integers xix_i and yiy_i, indicating that intersection (xi,yi)(x_i, y_i) is under construction. They satisfy 1≤xi,yi≤161 \le x_i, y_i \le 16.

Output

Print a single line containing only mm, the number of Taro's commute routes.

Hint

The figure below shows the case a=5a = 5, b=4b = 4, n=3n = 3, where the intersections under construction are (2,2)(2, 2), (2,3)(2, 3), and (4,2)(4, 2).

In this case there are m=5m = 5 commute routes. All five routes are illustrated below.

Examples1

  1. Example 1

    Input
    5 4
    3
    2 2
    2 3
    4 2
    
    Expected output
    5