Under construction

Still being built. Things may change

Goat Rope

Interview

Time limit2sMemory limit512 MB

Summary
Given a point outside an axis-aligned rectangle, print the minimum distance from the point to the rectangle's boundary.
Level

Medium4 of 10

Topics
Geometry, Math, Implementation
Solved
No attempts yet

Problem

You have a fence post at the point (x,y)(x, y) in the plane, and a goat is tethered to it by a rope. You also have a house, which you model as an axis-aligned rectangle with diagonally opposite corners at the points (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2). You want to choose a rope length that guarantees the goat cannot reach the house. Find the minimum distance from the post to the house, so that you can be sure to use a shorter rope.

Input

The input consists of a single line containing six space-separated integers xx, yy, x1x_1, y1y_1, x2x_2, and y2y_2, each in the range [−999,999][-999, 999].

It is guaranteed that x1<x2x_1 < x_2 and y1<y2y_1 < y_2, and that (x,y)(x, y) lies strictly outside the axis-aligned rectangle with corners at (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2).

Output

Print the minimum distance from the goat's post to the house, with a relative or absolute error of at most 0.0010.001.

Examples5

  1. Example 1

    Input
    7 3 0 0 5 4
    
    Expected output
    2.0
    
  2. Example 2

    Input
    6 0 0 2 7 6
    
    Expected output
    2.0
    
  3. Example 3

    Input
    3 -4 -3 -1 -1 2
    
    Expected output
    5.0
    
  4. Example 4

    Input
    7 4 0 0 5 4
    
    Expected output
    2.000
    
  5. Example 5

    Input
    4 8 7 8 9 9
    
    Expected output
    3.000