102562: [AtCoder]ABC256 C - Filling 3x3 array

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $300$ points

Problem Statement

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

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$

Output

Print the number of ways to write numbers to satisfy the conditions.


Sample Input 1

3 4 6 3 3 7

Sample Output 1

1

The following is the only way to satisfy the conditions. Thus, $1$ should be printed.

image2


Sample Input 2

3 4 5 6 7 8

Sample Output 2

0

There may not be a way to satisfy the conditions.


Sample Input 3

5 13 10 6 13 9

Sample Output 3

120

Sample Input 4

20 25 30 22 29 24

Sample Output 4

30613

Input

题意翻译

### 题目描述 给你六个正整数 $h_1,h_2,h_3$ 以及 $w_1,w_2,w_3$,请构造出一个 $3 \times 3$ 的**正整数**方阵,使得: - 方阵内的数均为正整数; - 对于上起第 $i$ 行中的三个整数,满足:它们的和与 $h_i$ 相等; - 对于左起第 $i$ 列中的三个整数,满足:它们的和与 $w_i$ 相等。 请求出满足条件的构造方案数。 ### 输入格式 一行六个整数 $h_1,h_2,h_3,w_1,w_2,w_3$,相邻的两个整数之间以单个空格隔开。 ### 输出格式 一行一个非负整数,即构造方案数。 ### 说明/提示 #### 输入输出样例 #1 说明 只有如图一种方案,所以输出 $1$。 ![样例 #1 方案](https://img.atcoder.jp/ghi/d53ea47321716fe799854c72b7beff3c.jpg) #### 输入输出样例 #2 说明 可能没有办法满足条件。 #### 数据规模与约定 $3 \le $ 输入中的所有数 $ \le 30$ 且输入均为整数。

Output

得分:$300$分

问题描述

给你六个整数:$h_1, h_2, h_3, w_1, w_2$和$w_3$。

  • 对于$i=1,2,3$,从上数的第$i$行的数字之和为$h_i$。
  • 对于$j=1,2,3$,从左数的第$j$列的数字之和为$w_i$。

例如,如果$(h_1, h_2, h_3) = (5, 13, 10)$和$(w_1, w_2, w_3) = (6, 13, 9)$,则满足条件的所有方式如下所示。 (还有其他满足条件的方式)。

image

有多少种方式可以写数字来满足条件?

约束条件

  • $3 \leq h_1, h_2, h_3, w_1, w_2, w_3 \leq 30$
  • 输入中的所有值都是整数。

输入

从标准输入以以下格式获取输入:

$h_1$ $h_2$ $h_3$ $w_1$ $w_2$ $w_3$

输出

打印满足条件的写数字的方式的数量。


样例输入1

3 4 6 3 3 7

样例输出1

1

以下仅有一种方式可以满足条件。 因此,应该打印$1$。

image2


样例输入2

3 4 5 6 7 8

样例输出2

0

可能没有满足条件的方式。


样例输入3

5 13 10 6 13 9

样例输出3

120

样例输入4

20 25 30 22 29 24

样例输出4

30613

加入题单

算法标签: