Hide

Problem L
Last Goal

In the 2025 Pokeathlon World Cup, the clock ticks into the 90th minute. The stadium is deafening, the tension is unbearable — Team Pingu is locked in a dead heat with their rivals. The ball is at the feet of their captain, the indomitable Piplup. He eyes the goal, calculating the perfect shot. The crowd holds its breath. He takes aim — AND STRIKES! The ball rockets forward, slicing through the air like a missile. Time slows as it hurtles toward the net… AND IT’S IN! GOOOOOOAL! The fans erupt in wild celebration as Piplup delivers the match-winning strike!

The goal area can be treated as a rectangle with walls on three of its sides. Since Piplup is incredibly strong, the ball will not lose speed upon hitting the sides of the goal but will instead perfectly reflect off the walls. You are tasked with capturing a photo of this incredible match-winning shot. To get the perfect image, you plan to stand just behind the goal. However, you are afraid that the ball might hit your $100,000 camera. Thus, you must calculate where the ball will impact the back wall of the goal so that you can position yourself as far away as possible while still being directly behind the wall.

You are given the location where Piplup made the shot and the point at which he was aiming. (The aiming point may be behind the goal.) Note that it is guaranteed that the ball, following a straight line, will go into the goal and eventually hit the back wall. (As Piplup had secretly used the move Lock-On prior to taking the shot.) Please determine the farthest distance from any point on the back wall to the point where the ball will hit the back wall of the goal. (Please refer to sample explanation for a clearer picture.)

Input

The first four lines of input each contain two integers, $X_i, Y_i$ ($-10^9 \leq X_i, Y_i \leq 10^9$), representing the goal area in counterclockwise order, with $(X_2, Y_2) - (X_3, Y_3)$ being the back wall of the goal.

The next line of input contains four integers, $A, B, C, D$ ($-10^9 \leq A, B, C, D \leq 10^9$), indicating that the ball will start from $(A, B)$ and move towards $(C, D)$ until it reaches the goal.

It is guaranteed the ball is not within the goal, inclusive of the boundary. The path the ball follows is also guaranteed to hit the back of the goal. (Yes we are very nice.)

Output

Output a single values representing the farthest distance you can be from point of impact of the ball against the back wall. Given that you are still somewhere on the back wall.

Your answer is considered correct if its absolute or relative error does not exceed $10^{-3}$. Formally, let your answer be $a$, and the jury’s answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max (1, b)}\leq 10^{-3}$.

Sample Explanation

\includegraphics[width=0.6\textwidth ]{bounce.png}

For the first sample: The goal is the black rectangle with 3 sides filled in. The blue + red path is the path taken by the ball. You can stand at one of the edge of the back wall, being $1$ unit distance away from the point of impact.

\includegraphics[width=0.5\textwidth ]{bounce2.png}

For the second sample: The goal is the black rectangle with 3 sides filled in. The blue + red path is the path taken by the ball. Note that the aiming point can be behind the goal, but the ball will hit the wall of the goal first. You can stand at point $(5, 6)$ on the back wall,which is the farthest away from the point of impact, with a distance of $1.42295$ units.

Sample Input 1 Sample Output 1
2 2
2 0
4 0
4 2
0 3 3 2
1.00000000000
Sample Input 2 Sample Output 2
2 2
6 4
5 6
1 4
0 0 6 10
1.42295234932

Please log in to submit a solution to this problem

Log in