Under construction

Still being built. Things may change

Carl's Vacation

Time limit1sMemory limit1024 MB

Summary
Find the shortest walk between the apexes of two right square pyramids, moving only on their faces and the ground plane.
Level

Hard8 of 10

Topics
Geometry, Shortest path, Math
Solved
No attempts yet

Problem

Carl the ant is back! After winding through meandering paths (Problem A, 2004 World Finals) and wandering over octahedrons (Problem C, 2009 World Finals), it is time for a little vacation. Time to see the sights! And where better to see the sights than at the tips of tall structures like pyramids? And where better to see tall pyramids than Egypt? (This is so exciting!!!!)

After taking in the view from the tip of one pyramid, Carl wants to go to the tip of another. Ants do not handle the hot sun well, so he wants the minimum distance between the tips of the two pyramids. Carl can only walk on the surfaces of the pyramids and on the plane the pyramids sit upon. Each pyramid is a right square pyramid, meaning the apex lies directly above the center of a square base.

Figure 1: Illustration of two pyramids corresponding to Sample Input 1. The black line shows the shortest path between their apexes.

Input

The first line contains five integers x1x_1, y1y_1, x2x_2, y2y_2, hh. The points (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) define an edge of the first pyramid, with the body of the pyramid to the left of the directed vector from (x1,y1)(x_1, y_1) to (x2,y2)(x_2, y_2). hh is the height of the pyramid. The second line describes the second pyramid in the same format. The bases of the two pyramids have an intersection of area 0.

Constraints: −105≤x1,y1,x2,y2≤105-10^5 \le x_1, y_1, x_2, y_2 \le 10^5, (x1,y1)≠(x2,y2)(x_1, y_1) \ne (x_2, y_2), 1≤h≤1051 \le h \le 10^5.

Output

Output the minimum distance Carl travels between the tips of the two pyramids. An absolute or relative error of at most 10−610^{-6} is accepted.

Examples1

  1. Example 1

    Input
    0 0 10 0 4
    9 18 34 26 42
    
    Expected output
    60.866649532