cho.sh
Notes
Loading...

Number of Roads

Time limit

2s

Memory limit

16 MB

Problem

A city is shaped like a rectangular grid. The grid points range from 0 to N in the horizontal direction and from 0 to M in the vertical direction. The home is at (0, 0), and the school is at (N, M).

Only shortest paths are allowed, so every valid route moves exactly N + M times, using only moves to the right or upward. However, some roads between adjacent grid points are under construction and cannot be used.

Find the number of different shortest paths from (0, 0) to (N, M) that do not use any road under construction.

Input

The first line contains the horizontal size N and the vertical size M of the city. N and M are natural numbers not greater than 100.

The second line contains K, the number of roads under construction. K is an integer between 0 and 50, inclusive.

Each of the next K lines contains four integers a b c d describing one road under construction. This means the road connecting (a, b) and (c, d) cannot be used. The values a and c are between 0 and N, inclusive, and b and d are between 0 and M, inclusive. The distance between the two points is always 1.

Output

Print the number of different shortest paths from (0, 0) to (N, M). The answer is between 0 and 2^63 - 1, inclusive.