Three-dimensional pinball in zero gravity
The company "Pinball'Co", known for its arcade machine production, has designed an innovative game called "Three-Dimensional Pinball in Zero Gravity". This game is set within a rectangular box with dimensions A, B, and C, where complete weightlessness is maintained. The objective for the player is to launch a ball from a starting point in a chosen direction, allowing it to fly freely and touch as many different walls of the box as possible, aiming to hit a bonus point. The bonus point only appears if the ball has contacted all the walls, but its location is known beforehand. The ball maintains its speed throughout the flight, and upon hitting the walls, it bounces off them perfectly elastically. For each new wall the ball touches, the player earns P points. The game concludes if the ball touches any wall again or reaches the bonus point. In the latter scenario, the player receives an additional bonus calculated as P/D, where D is the total distance traveled by the ball. The creators of the game are curious about the maximum bonus achievable, given the dimensions of the box and the specified initial and bonus points. They need a program to determine this. Since Vanya is currently occupied and unable to assist, the engineers at "Pinball'Co" were disappointed. However, they heard about the talented programmers at "Krone" and decided to seek your help.
Your task is to compute the maximum bonus attainable by launching the ball in any direction, given the parameters of the rectangular box, the initial position of the ball (considered as a point for simplicity), and the coordinates of the bonus point.
The coordinate system is set such that the origin coincides with one vertex of the box, and the axes extend towards the three vertices sharing common faces with it. When the ball collides with a wall, it changes direction according to the reflection law. If the ball hits a face, it is considered to have touched 2 sides connected by that face. It bounces off both, and the player earns a bonus as if hitting 2 walls (if the ball has already touched at least one of these walls, the game ends, and no bonus is awarded for this collision). A collision with a vertex is treated as a collision with 3 sides to which the vertex belongs. Similarly, if the ball has already touched at least one of the walls connected to the vertex, the game ends, and no bonus is awarded for this collision.
Input
The first line of the input contains 3 positive integers: A, B, and C (2 ≤ A, B, C ≤ 1000), representing the lengths of the box along the OX, OY, and OZ axes, respectively.
The second line contains three positive integers: X_1, Y_1, and Z_1, indicating the initial coordinates of the ball within the box.
The third line contains three positive integers: X_B, Y_B, and Z_B, specifying the coordinates where the bonus point appears. All coordinates satisfy 0 < X < A, 0 < Y < B, 0 < Z < C.
The fourth line contains a single positive integer: the bonus value P (1 ≤ P ≤ 1000).
Output
The output should be a single number on the first line, representing the maximum possible bonus that can be achieved with the given game parameters, rounded to 4 decimal places.