codeforces-scrape

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

231D.md (3098B)


      1 Source: https://codeforces.com/problemset/problem/231/D
      2 
      3 D. Magic Box
      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 One day Vasya was going home when he saw a box lying on the road. The box can be represented as a rectangular parallelepiped. Vasya needed no time to realize that the box is special, as all its edges are parallel to the coordinate axes, one of its vertices is at point (0, 0, 0), and the opposite one is at point (*x*1, *y*1, *z*1). The six faces of the box contain some numbers *a*1, *a*2, ..., *a*6, exactly one number right in the center of each face.
     22 
     23  ![](https://espresso.codeforces.com/99ec402a76236b249daa9d873b2e3ad0f03e114c.png) 
     24 
     25 The numbers are located on the box like that:
     26 
     27 * number *a*1 is written on the face that lies on the ZOX plane;
     28 * *a*2 is written on the face, parallel to the plane from the previous point;
     29 * *a*3 is written on the face that lies on the XOY plane;
     30 * *a*4 is written on the face, parallel to the plane from the previous point;
     31 * *a*5 is written on the face that lies on the YOZ plane;
     32 * *a*6 is written on the face, parallel to the plane from the previous point.
     33 
     34 At the moment Vasya is looking at the box from point (*x*, *y*, *z*). Find the sum of numbers that Vasya sees. Note that all faces of the box are not transparent and Vasya can't see the numbers through the box. The picture contains transparent faces just to make it easier to perceive. You can consider that if Vasya is looking from point, lying on the plane of some face, than he can not see the number that is written on this face. It is enough to see the center of a face to see the corresponding number for Vasya. Also note that Vasya always reads correctly the *a**i* numbers that he sees, independently of their rotation, angle and other factors (that is, for example, if Vasya sees some *a**i* = 6, then he can't mistake this number for 9 and so on).
     35 
     36 Input
     37 
     38 The fist input line contains three space-separated integers *x*, *y* and *z* (|*x*|, |*y*|, |*z*| ≤ 106) — the coordinates of Vasya's position in space. The second line contains three space-separated integers *x*1, *y*1, *z*1 (1 ≤ *x*1, *y*1, *z*1 ≤ 106) — the coordinates of the box's vertex that is opposite to the vertex at point (0, 0, 0). The third line contains six space-separated integers *a*1, *a*2, ..., *a*6 (1 ≤ *a**i* ≤ 106) — the numbers that are written on the box faces.
     39 
     40 It is guaranteed that point (*x*, *y*, *z*) is located strictly outside the box.
     41 
     42 Output
     43 
     44 Print a single integer — the sum of all numbers on the box faces that Vasya sees.
     45 
     46 Examples
     47 
     48 Input
     49 
     50 ```
     51 2 2 2  
     52 1 1 1  
     53 1 2 3 4 5 6
     54 ```
     55 
     56 Output
     57 
     58 ```
     59 12
     60 ```
     61 
     62 Input
     63 
     64 ```
     65 0 0 10  
     66 3 2 3  
     67 1 2 3 4 5 6
     68 ```
     69 
     70 Output
     71 
     72 ```
     73 4
     74 ```
     75 
     76 Note
     77 
     78 The first sample corresponds to perspective, depicted on the picture. Vasya sees numbers *a*2 (on the top face that is the darkest), *a*6 (on the right face that is the lightest) and *a*4 (on the left visible face).
     79 
     80 In the second sample Vasya can only see number *a*4.