Problem2357--C - Filling 3x3 array

2357: C - Filling 3x3 array

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 128 MB

Description

Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 300300 points

Problem Statement

You are given six integers: h_1, h_2, h_3, w_1, w_2h1,h2,h3,w1,w2, and w_3w3.




Consider writing a positive integer on each square of a 3 \times 33×3 grid so that all of the following conditions are satisfied:
  • For i=1,2,3i=1,2,3, the sum of numbers written in the ii-th row from the top is h_ihi.
  • For j=1,2,3j=1,2,3, the sum of numbers written in the jj-th column from the left is w_iwi.
For example, if (h_1, h_2, h_3) = (5, 13, 10)(h1,h2,h3)=(5,13,10) and (w_1, w_2, w_3) = (6, 13, 9)(w1,w2,w3)=(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 303h1,h2,h3,w1,w2,w330
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:
h_1h1h_2h2h_3h3w_1w1w_2w2w_3w3

Output

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

Sample Input Copy

3 4 6 3 3 7

Sample Output Copy

1

HINT

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

image2

Source/Category