Filling 3x3 array

AtCoder
IDabc256_c
Time2000ms
Memory256MB
Difficulty
You are given six integers: $h_1, h_2, h_3, w_1, w_2$, and $w_3$. Consider writing a **positive** integer on each square of a $3 \times 3$ grid so that all of the following conditions are satisfied: * For $i=1,2,3$, the sum of numbers written in the $i$\-th row from the top is $h_i$. * For $j=1,2,3$, the sum of numbers written in the $j$\-th column from the left is $w_i$. For example, if $(h_1, h_2, h_3) = (5, 13, 10)$ and $(w_1, w_2, w_3) = (6, 13, 9)$, then all of the following three ways satisfy the conditions. (There are other ways to satisfy the conditions.) ![image](https://img.atcoder.jp/ghi/42e99457e52ca5e6d335b2dbda72d9ab.png) How many ways are there to write numbers to satisfy the conditions? ## Constraints * $3 \leq h_1, h_2, h_3, w_1, w_2, w_3 \leq 30$ * All values in input are integers. ## Input Input is given from Standard Input in the following format: $h_1$ $h_2$ $h_3$ $w_1$ $w_2$ $w_3$ [samples]
Samples
Input #1
3 4 6 3 3 7
Output #1
1

The following is the only way to satisfy the conditions. Thus, $1$ should be printed.
![image](https://img.atcoder.jp/ghi/d53ea47321716fe799854c72b7beff3c.jpg)
Input #2
3 4 5 6 7 8
Output #2
0

There may not be a way to satisfy the conditions.
Input #3
5 13 10 6 13 9
Output #3
120
Input #4
20 25 30 22 29 24
Output #4
30613
API Response (JSON)
{
  "problem": {
    "name": "Filling 3x3 array",
    "description": {
      "content": "You are given six integers: $h_1, h_2, h_3, w_1, w_2$, and $w_3$.   Consider writing a **positive** integer on each square of a $3 \\times 3$ grid so that all of the following conditions are satisfied:",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc256_c"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given six integers: $h_1, h_2, h_3, w_1, w_2$, and $w_3$.  \nConsider writing a **positive** integer on each square of a $3 \\times 3$ grid so that all of the following conditions are satisfied:...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments