codeforces-scrape

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

143A.md (3351B)


      1 Source: https://codeforces.com/problemset/problem/143/A
      2 
      3 A. Help Vasilisa the Wise 2
      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 Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that.
     22 
     23 The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2 × 2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below.
     24 
     25  ![](https://espresso.codeforces.com/127c7d97f5f9a5325756ac217e39f1c13877c4c5.png) 
     26 
     27 The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below.
     28 
     29  ![](https://espresso.codeforces.com/393eab7d3f4fec2231447807c31dcde2fce6a958.png) 
     30 
     31 Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task.
     32 
     33 Input
     34 
     35 The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers *r*1 and *r*2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers *c*1 and *c*2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers *d*1 and *d*2 that define the required sums of numbers on the main and on the side diagonals of the square (1 ≤ *r*1, *r*2, *c*1, *c*2, *d*1, *d*2 ≤ 20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement.
     36 
     37  ![](https://espresso.codeforces.com/4073cdd8ce49caace5c671d9455b35a21156a336.png)
     38 
     39 Output
     40 
     41 Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
     42 
     43 If there are several solutions, output any.
     44 
     45 Examples
     46 
     47 Input
     48 
     49 ```
     50 3 7  
     51 4 6  
     52 5 5
     53 ```
     54 
     55 Output
     56 
     57 ```
     58 1 2  
     59 3 4
     60 ```
     61 
     62 Input
     63 
     64 ```
     65 11 10  
     66 13 8  
     67 5 16
     68 ```
     69 
     70 Output
     71 
     72 ```
     73 4 7  
     74 9 1
     75 ```
     76 
     77 Input
     78 
     79 ```
     80 1 2  
     81 3 4  
     82 5 6
     83 ```
     84 
     85 Output
     86 
     87 ```
     88 -1
     89 ```
     90 
     91 Input
     92 
     93 ```
     94 10 10  
     95 10 10  
     96 10 10
     97 ```
     98 
     99 Output
    100 
    101 ```
    102 -1
    103 ```
    104 
    105 Note
    106 
    107 Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9.