codeforces-scrape

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

57A.md (1400B)


      1 Source: https://codeforces.com/problemset/problem/57/A
      2 
      3 A. Square Earth?
      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 Meg the Rabbit decided to do something nice, specifically — to determine the shortest distance between two points on the surface of our planet. But Meg... what can you say, she wants everything simple. So, she already regards our planet as a two-dimensional circle. No, wait, it's even worse — as a square of side *n*. Thus, the task has been reduced to finding the shortest path between two dots on a square (the path should go through the square sides). To simplify the task let us consider the vertices of the square to lie at points whose coordinates are: (0, 0), (*n*, 0), (0, *n*) and (*n*, *n*).
     22 
     23 Input
     24 
     25 The single line contains 5 space-separated integers: *n*, *x*1, *y*1, *x*2, *y*2 (1 ≤ *n* ≤ 1000, 0 ≤ *x*1, *y*1, *x*2, *y*2 ≤ *n*) which correspondingly represent a side of the square, the coordinates of the first point and the coordinates of the second point. It is guaranteed that the points lie on the sides of the square.
     26 
     27 Output
     28 
     29 You must print on a single line the shortest distance between the points.
     30 
     31 Examples
     32 
     33 Input
     34 
     35 ```
     36 2 0 0 1 0
     37 ```
     38 
     39 Output
     40 
     41 ```
     42 1
     43 ```
     44 
     45 Input
     46 
     47 ```
     48 2 0 1 2 1
     49 ```
     50 
     51 Output
     52 
     53 ```
     54 4
     55 ```
     56 
     57 Input
     58 
     59 ```
     60 100 0 0 100 100
     61 ```
     62 
     63 Output
     64 
     65 ```
     66 200
     67 ```