Under construction

Still being built. Things may change

Three-way Branch

Time limit7sMemory limit64 MB

Summary
Count three-way downward paths from (1,1) to (W,H) on a grid with up to 30 blocked cells, modulo 1000000009.
Level

Medium7 of 10

Topics
Dynamic programming, Matrix
Solved
No attempts yet

Problem

There is a grid of WW columns and HH rows. The upper left cell is (1,1)(1, 1): the first coordinate grows to the right and the second coordinate grows downward. You stand on (1,1)(1, 1) and you want to reach (W,H)(W, H).

From cell (x,y)(x, y) you may move only to the cell below and to the left (x−1,y+1)(x - 1, y + 1), the cell directly below (x,y+1)(x, y + 1), or the cell below and to the right (x+1,y+1)(x + 1, y + 1).

Some cells hold an obstruction. You cannot move onto an obstructed cell, and you cannot leave the grid. Write a program that prints the number of paths reaching (W,H)(W, H), modulo 1,000,000,009. The cell (1,1)(1, 1) never holds an obstruction.

Input

The input holds several test cases.

The first line of each test case has the width WW, the height HH, and the number of obstructions NN, separated by spaces. (1≤W≤751 \le W \le 75, 2≤H≤10182 \le H \le 10^{18}, 0≤N≤300 \le N \le 30)

Each of the next NN lines has the position xix_i, yiy_i of one obstruction. (1≤xi≤W1 \le x_i \le W, 1≤yi≤H1 \le y_i \le H)

The line after the last test case holds three zeros.

Output

For each test case, print one line with the case number and the number of paths reaching (W,H)(W, H), modulo 1,000,000,009. If the answer of the kk-th test case is aa, print it in the form Case k: a.

Examples1

  1. Example 1

    Input
    2 4 1
    2 1
    2 2 1
    2 2
    0 0 0
    
    Expected output
    Case 1: 4
    Case 2: 0