Unfortunately Leyang was not able to prove his superiority in math because he, well, didn't do so good on math contest. However, he thinks he can redeem himself by solving this problem, called More Meth! The problem is as follows:
There is a cube in which we define the x,y,z
axis to start from one vertex of the cube and extend the axis’ positive side from the sides of the cube.
An ant travels on this cube of side length N
, where (1 <= N <= 10^6
). This ant can be viewed as a point for the sake of this question. This cube is very weak on the inside so that the ant is able to gnaw a straight path to his destination. But behold, the cube has a tough outer shell with 1 weak point which is at the center of the top face. The ant must first travel from the point (A,B,C)
, which is guaranteed to be on the surface of the cube, to the weak point of the cube, and then travel to point (M,N,O)
, which is guaranteed to be inside the cube.
Your task is to calculate the shortest distance he must travel given the values.
The first line will contain N, the side length of the cube
The second line will contain A,B, and C separated by a single space
The third line will contain M, N, and O separated by a single space
In one line, output the distance to the nearest thousandth
2
0 0 1
1 1 1
4.000
Note that despite proper notation, the top center point in this problem is actually defined as (n/2, n, n/2) rather than (n/2, n/2, n).
Reply