Under construction

Still being built. Things may change

Maxplus

Time limit1sMemory limit128 MB

Summary
Given 3x3 integer matrices A and C, find the entrywise-largest integer matrix B with A (max-plus) B = C, or report that none exists.
Level

Hard8 of 10

Topics
Math, Matrix, Greedy, Implementation
Solved
No attempts yet

Problem

Max-plus algebra works over the real numbers with only two binary operations: the maximum operation ⊕\oplus and the addition operation ⊗\otimes. The operation ⊗\otimes binds tighter than ⊕\oplus.

x⊕y=max⁡(x,y),x⊗y=x+yx \oplus y = \max(x, y), \qquad x \otimes y = x + y

For example, 3⊕5=53 \oplus 5 = 5, 7⊕4=77 \oplus 4 = 7, 3⊗5=83 \otimes 5 = 8, and 7⊗4=117 \otimes 4 = 11.

Applications of this algebra often use the max-plus product of two matrices, A⊗B=CA \otimes B = C. The product is defined the same way as the ordinary matrix product, except that the multiplication sign becomes ⊗\otimes (addition) and the addition sign becomes ⊕\oplus (maximum).

This problem only deals with the max-plus product of 3×33 \times 3 integer matrices.

[a1,1a1,2a1,3a2,1a2,2a2,3a3,1a3,2a3,3]⊗[b1,1b1,2b1,3b2,1b2,2b2,3b3,1b3,2b3,3]=[c1,1c1,2c1,3c2,1c2,2c2,3c3,1c3,2c3,3]\begin{bmatrix} a_{1,1} & a_{1,2} & a_{1,3} \\ a_{2,1} & a_{2,2} & a_{2,3} \\ a_{3,1} & a_{3,2} & a_{3,3} \end{bmatrix} \otimes \begin{bmatrix} b_{1,1} & b_{1,2} & b_{1,3} \\ b_{2,1} & b_{2,2} & b_{2,3} \\ b_{3,1} & b_{3,2} & b_{3,3} \end{bmatrix} = \begin{bmatrix} c_{1,1} & c_{1,2} & c_{1,3} \\ c_{2,1} & c_{2,2} & c_{2,3} \\ c_{3,1} & c_{3,2} & c_{3,3} \end{bmatrix}

Here ci,j=ai,1⊗b1,j⊕ai,2⊗b2,j⊕ai,3⊗b3,jc_{i,j} = a_{i,1} \otimes b_{1,j} \oplus a_{i,2} \otimes b_{2,j} \oplus a_{i,3} \otimes b_{3,j}, so ci,jc_{i,j} is the largest of the three sums of matching entries.

For example, the following holds.

[0123−10111]⊗[201−132010]=[243534343]\begin{bmatrix} 0 & 1 & 2 \\ 3 & -1 & 0 \\ 1 & 1 & 1 \end{bmatrix} \otimes \begin{bmatrix} 2 & 0 & 1 \\ -1 & 3 & 2 \\ 0 & 1 & 0 \end{bmatrix} = \begin{bmatrix} 2 & 4 & 3 \\ 5 & 3 & 4 \\ 3 & 4 & 3 \end{bmatrix}

You are given the matrices AA and CC. Every entry of both matrices is an integer with absolute value less than 100. Write a program that finds a matrix BB whose entries are integers with absolute value less than 1000 and that satisfies A⊗B=CA \otimes B = C, or reports that no such matrix exists.

Input

The first three lines contain three integers each, the matrix AA.

The next three lines contain three integers each, the matrix CC.

Every number is an integer with absolute value less than 100.

Output

If no matrix BB satisfies A⊗B=CA \otimes B = C, print nemoguce on the first and only line.

Otherwise print the matrix BB on three lines, three integers per line, separated by single spaces.

Several matrices can satisfy A⊗B=CA \otimes B = C. Print the one whose every entry is greater than or equal to the entry in the same position of every other valid matrix. Whenever at least one valid matrix exists, that matrix exists and is unique, and all of its entries have absolute value less than 1000.

Examples3

  1. Example 1

    Input
    1 2 3
    2 3 1
    3 1 4
    6 5 6
    6 4 6
    7 6 7
    
    Expected output
    4 2 4
    3 1 3
    3 2 3
    
  2. Example 2

    Input
    0 0 0
    0 0 0
    0 0 0
    99 99 99
    99 99 99
    99 99 99
    
    Expected output
    99 99 99
    99 99 99
    99 99 99
    
  3. Example 3

    Input
    1 1 1
    1 1 1
    1 1 1
    2 2 2
    2 3 2
    2 2 2
    
    Expected output
    nemoguce