There are twelve types of tiles in Fig. 1. You were asked to fill a table with R × C cells with these tiles. R is the number of rows and C is the number of columns.
How many arrangements in the table meet the following constraints?
Each cell has one tile.
the center of the upper left cell (1,1) and the center of the lower right cell (C, R) are connected by some roads.
The first line contains two integers R and C (2 ≤ R × C ≤ 15).
You can safely assume at least one of R and C is greater than 1.
The second line contains twelve integers, t1, t2, ..., t12 (0 ≤ t1 + .... + t12 ≤ 15).
ti represents the number of the i-th tiles you have.
Output the number of arrangments in a line.
3 3 4 2 2 0 0 0 0 0 0 0 0 1
2
3 3 0 1 1 0 0 0 0 0 0 0 0 7
66
3 3 0 0 0 0 0 0 0 0 0 0 0 10
1
2 4 0 0 1 1 1 2 0 1 0 0 1 1
2012
5 2 0 1 1 1 0 1 2 1 2 0 0 1
8512