Pipeline Plans
시간 제한5초메모리 제한512 MB
타일을 R×C 격자에 배치해 왼쪽 위 칸 중심과 오른쪽 아래 칸 중심이 도로로 이어지는 경우의 수를 센다.
문제
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.

Fig. 1: the types of tiles
입력
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.