eolymp
bolt
Try our new interface for solving problems
Problems

Rabbit`s planet

Rabbit`s planet

The planet where rabbits live is not much different from ours. It has wonderful nature. It is the third planet from Rabbitus Beta Megastar. Biggest difference is that rabbit’s planet has a shape of cube with side \textbf{R}. This is strange. But rabbits like it, since at their opinion it simplifies navigation at the planet. You need to check how easier it is to live at cubic planet. Try to calculate the shortest distance between \textbf{2} points at the planet like this. \InputFile The only line at the input contains seven integers, separated by spaces: \textbf{R}, \textbf{x_1}, \textbf{y_1}, \textbf{z_1}, \textbf{x_2}, \textbf{y_2}, \textbf{z_\{2 \}}(\textbf{1} ≤ \textbf{R} ≤ \textbf{100000}, \textbf{0 }≤ \textbf{x_1},\textbf{y_1}, \textbf{z_1}, \textbf{x_2}, \textbf{y_2}, \textbf{z_2} ≤ \textbf{R}) -- correspondingly, side of the cube and coordinates of points. Two opposite vertexes of the cube are located at points (\textbf{0}, \textbf{0}, \textbf{0}) and (\textbf{R}, \textbf{R}, \textbf{R}), all sides are parallel to the coordinate axis. All points at input belong to cube’s surface. \OutputFile You need to output one number -- distance between specified points going by planet's surface, rounded to closest integer.
Time limit 1 second
Memory limit 64 MiB
Input example #1
1 0 0 0 1 0 0
Output example #1
1
Source ACM-ICPC Ukraine 2012, 1st Stage Ukraine, April 21, 2012