#chokudai004a. [chokudai004_a]Just Write Numbers!

[chokudai004_a]Just Write Numbers!

Problem Statement

Takahashi loves three integers B1B_1, B2B_2, and B3B_3.

He will write integers in an NtimesNN \\times N grid so that it will contain many vertical or horizontal contiguous segments whose sums are his favorite numbers.

For example, if he writes numbers as follows and his favorite number is 1313, the segments painted red have the desired sum.

Let A1,A2,A3A_1, A_2, A_3 be the number of vertical or horizontal segments whose sums are B1,B2,B3B_1, B_2, B_3, respectively. He will then get $A_1 \\times B_1 + A_2 \\times B_2 + A_3 \\times B_3$ points.

However, there are some limitations to what Takahashi can write in the grid. On each square, he must write a number between the lower and upper limits specified for that square.

On the square at the ii-th row from the top and jj-th column from the left, he must write a number between li,jl_{i,j} and ri,jr_{i,j} (inclusive).

Find a way to write numbers so that Takahashi gets as many points as possible.

This is a so-called "marathon" problem where you are not assumed to find the optimal solution. Any valid solution will get a score.

Constraints

  • N=30N = 30
  • 10leqB1leq1910 \\leq B_1 \\leq 19
  • 20leqB1leq2920 \\leq B_1 \\leq 29
  • 30leqB1leq3930 \\leq B_1 \\leq 39
  • 1leqli,jleqri,jleq91 \\leq l_{i,j} \\leq r_{i,j} \\leq 9

Input

Input is given from Standard Input in the following format:

NN B1B_1 B2B_2 B3B_3 l1,1l_{1,1} l1,2l_{1,2} ldots\\ldots l1,Nl_{1,N} l2,1l_{2,1} l2,2l_{2,2} ldots\\ldots l2,Nl_{2,N} :: lN,1l_{N,1} lN,2l_{N,2} ldots\\ldots lN,Nl_{N,N} r1,1r_{1,1} r1,2r_{1,2} ldots\\ldots r1,Nr_{1,N} r2,1r_{2,1} r2,2r_{2,2} ldots\\ldots r2,Nr_{2,N} :: rN,1r_{N,1} rN,2r_{N,2} ldots\\ldots rN,Nr_{N,N}

Output

Let Ai,jA_{i,j} be the number to write the square at the ii-th row and jj-th column. Print your solution in the following format:

A1,1A_{1,1} A1,2A_{1,2} ldots\\ldots A1,NA_{1,N} A2,1A_{2,1} A2,2A_{2,2} ldots\\ldots A2,NA_{2,N} :: AN,1A_{N,1} AN,2A_{N,2} ldots\\ldots AN,NA_{N,N}

Your solution will be considered valid if li,jleqAi,jleqri,jl_{i,j} \\leq A_{i,j} \\leq r_{i,j} for every Ai,jA_{i,j}, and will get a score according to the Problem Statement.

If your output is not considered a valid solution, it will get 00 points in almost all test cases.

Input Generation

  • BB will be generated uniformly at random within the range specified in Constraints.
  • li,jl_{i,j} and ri,jr_{i,j} will be generated uniformly at random between 11 and 99 (inclusive), independently for each square. If li,jl_{i,j} gets greater than ri,jr_{i,j}, they will be swapped.

Sample Input, Output, and Others

Sample Input, Output (Example01 through 03), and a program (C++) to verify inputs and outputs are available here.