codeforces-scrape

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

675B.md (2421B)


      1 Source: https://codeforces.com/problemset/problem/675/B
      2 
      3 B. Restoring Painting
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. He remembers some facts about it.
     22 
     23 * The painting is a square 3 × 3, each cell contains a single integer from 1 to *n*, and different cells may contain either different or equal integers.
     24 * The sum of integers in each of four squares 2 × 2 is equal to the sum of integers in the top left square 2 × 2.
     25 * Four elements *a*, *b*, *c* and *d* are known and are located as shown on the picture below.
     26 
     27 ![](https://espresso.codeforces.com/69b6e71a30a43d62478f8c701eb83af65cae4c77.png)
     28 
     29 Help Vasya find out the number of distinct squares the satisfy all the conditions above. Note, that this number may be equal to 0, meaning Vasya remembers something wrong.
     30 
     31 Two squares are considered to be different, if there exists a cell that contains two different integers in different squares.
     32 
     33 Input
     34 
     35 The first line of the input contains five integers *n*, *a*, *b*, *c* and *d* (1 ≤ *n* ≤ 100 000, 1 ≤ *a*, *b*, *c*, *d* ≤ *n*) — maximum possible value of an integer in the cell and four integers that Vasya remembers.
     36 
     37 Output
     38 
     39 Print one integer — the number of distinct valid squares.
     40 
     41 Examples
     42 
     43 Input
     44 
     45 ```
     46 2 1 1 1 2
     47 ```
     48 
     49 Output
     50 
     51 ```
     52 2
     53 ```
     54 
     55 Input
     56 
     57 ```
     58 3 3 1 2 3
     59 ```
     60 
     61 Output
     62 
     63 ```
     64 6
     65 ```
     66 
     67 Note
     68 
     69 Below are all the possible paintings for the first sample. ![](https://espresso.codeforces.com/1b080143491988c6341fdeec4f018af688f28dfb.png) ![](https://espresso.codeforces.com/6520e87d7d093e906e3728605d9f5db63de49200.png)
     70 
     71 In the second sample, only paintings displayed below satisfy all the rules. ![](https://espresso.codeforces.com/755d6953bc72adb7d62919cdae44fe4df2a45980.png) ![](https://espresso.codeforces.com/9f7e753ea8e0a6f656ec97220ec4b15e1d5bc623.png) ![](https://espresso.codeforces.com/4089012b4c3887d273cb380d1fd0265b752984fb.png) ![](https://espresso.codeforces.com/49ac2bae7fc7d6c4cae7402c6e654ecbd9d3711a.png) ![](https://espresso.codeforces.com/9e8fa53d16956a11eb7a1e22a078d3b2352a882c.png) ![](https://espresso.codeforces.com/64bbe903c79c18fb251bd816e50940371e2da449.png)