codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

259B.md (2019B)


      1 Source: https://codeforces.com/problemset/problem/259/B
      2 
      3 B. Little Elephant and Magic Square
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Little Elephant loves magic squares very much.
     22 
     23 A magic square is a 3 × 3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15.
     24 
     25  ![](https://espresso.codeforces.com/9f6cca6585e4968eca8176164cbb1d37b61a77b2.png) 
     26 
     27 The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105.
     28 
     29 Help the Little Elephant, restore the original magic square, given the Elephant's notes.
     30 
     31 Input
     32 
     33 The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes.
     34 
     35 It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105.
     36 
     37 Output
     38 
     39 Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105.
     40 
     41 It is guaranteed that there exists at least one magic square that meets the conditions.
     42 
     43 Examples
     44 
     45 Input
     46 
     47 ```
     48 0 1 1  
     49 1 0 1  
     50 1 1 0
     51 ```
     52 
     53 Output
     54 
     55 ```
     56 1 1 1  
     57 1 1 1  
     58 1 1 1
     59 ```
     60 
     61 Input
     62 
     63 ```
     64 0 3 6  
     65 5 0 5  
     66 4 7 0
     67 ```
     68 
     69 Output
     70 
     71 ```
     72 6 3 6  
     73 5 5 5  
     74 4 7 4
     75 ```