In this problem we consider a very simplified model of Barcelona city.

Barcelona can be represented as a plane with streets of kind $x = c$ and $y = c$ for every integer $c$ (that is, the rectangular grid). However, there is a detail which makes Barcelona different from Manhattan. There is an avenue called Avinguda Diagonal which can be represented as a the set of points $(x, y)$ for which $ax + by + c = 0$.

One can walk along streets, including the avenue. You are given two integer points $A$ and $B$ somewhere in Barcelona. Find the minimal possible distance one needs to travel to get to $B$ from $A$.


-----Input-----

The first line contains three integers $a$, $b$ and $c$ ($-10^9\leq a, b, c\leq 10^9$, at least one of $a$ and $b$ is not zero) representing the Diagonal Avenue.

The next line contains four integers $x_1$, $y_1$, $x_2$ and $y_2$ ($-10^9\leq x_1, y_1, x_2, y_2\leq 10^9$) denoting the points $A = (x_1, y_1)$ and $B = (x_2, y_2)$.


-----Output-----

Find the minimum possible travel distance between $A$ and $B$. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$.

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|)}} \le 10^{-6}$.


-----Examples-----
Input
1 1 -3
0 3 3 0

Output
4.2426406871

Input
3 1 -9
0 3 3 -1

Output
6.1622776602



-----Note-----

The first example is shown on the left picture while the second example us shown on the right picture below. The avenue is shown with blue, the origin is shown with the black dot. [Image]

Difficulty: interview

Starter code:

Solutions:
a, b, c = list(map(int, input().split()))
x1, y1, x2, y2 = list(map(int, input().split()))
ans0 = round(abs(x1 - x2) + abs(y1 - y2), 9)
if a * b ==0:
    print(ans0)
    raise SystemExit
x11 = (-c - b * y1) / a
y12 = (-c - a * x1) / b
x21 = (-c - b * y2) / a
y22 = (-c - a * x2) / b

ans1 = abs(x1 - x11) + abs(x21 - x2) + ((y2 - y1)**2 + (x21 - x11)**2)**0.5
ans2 = abs(y1 - y12) + abs(x21 - x2) + ((y2 - y12)**2 + (x21 - x1)**2)**0.5
ans3 = abs(y1 - y12) + abs(y2 - y22) + ((x1 - x2)**2 + (y12 - y22)**2)**0.5
ans4 = abs(x1 - x11) + abs(y22 - y2) + ((x11 - x2)**2 + (y1 - y22)**2)**0.5

ans0 = min(ans0, ans1, ans2, ans3, ans4)

print(round(ans0, 10))


a,b,c = list(map(int, input().split()))
x1, y1, x2, y2 = list(map(int, input().split()))
if a == 0 or b == 0:
    print(abs(x1 -x2) + abs(y1 - y2))
else:
    a = a / (-b)
    c = c / (-b)
    if (x1 <= x2 and y1 <= y2) or (x1 >= x2 and y1 >= y2):
        y1 = -y1
        y2 = -y2
        a = -a
        c = -c
        x1, x2, y1, y2 = min(x1, x2), max(x1, x2), max(y1, y2), min(y1, y2)
    ax = a
    bx = c
    ay = 1 / a
    by = - c / a
    ans = abs(x1 -x2) + abs(y1 - y2)
    Ax = ay * y1 + by
    Ay = ax * x1 + bx
    Bx = ay * y2 + by
    By = ax * x2 + bx
    ans = min(ans, abs(x1 - Ax) + abs(x2 - Bx) + ((Bx - Ax) ** 2 + (y1 - y2) ** 2)**0.5)
    ans = min(ans, abs(y1 - Ay) + abs(y2 - By) + ((By - Ay) ** 2 + (x1 - x2) ** 2)**0.5)
    ans = min(ans, abs(x1 - Ax) + abs(y2 - By) + ((x2 - Ax) ** 2 + (y1 - By) ** 2)**0.5)
    ans = min(ans, abs(x2 - Bx) + abs(Ay - y1) + ((Bx - x1) ** 2 + (Ay - y2) ** 2)**0.5)
    print(ans)

def left_is_not(fet, tip):
    s = 0
    fet += 1
    if tip == 0:
        fet = tip + 10
    return tip

a, b, c = list(map(int, input().split()))
x1, y1, x2, y2 = list(map(int, input().split()))
l = []
l.append(abs(y1-y2) + abs(x1-x2))

if a == 0 or b == 0:
    print(abs(y1-y2) + abs(x1-x2))
else:
    xA = (-b*y1 - c)/a
    xB = (-b*y2 - c)/a
    yA = (-a*x1 - c)/b
    yB = (-a*x2 - c)/b
    
    l.append(((xA-xB)**2 + (y1-y2)**2)**0.5 + abs(x1-xA) + abs(x2-xB))
    
    l.append(((x1-x2)**2 + (yA-yB)**2)**0.5 + abs(y1-yA) + abs(y2-yB))
    
    l.append(((x1-xB)**2 + (yA-y2)**2)**0.5 + abs(yA-y1) + abs(x2-xB))
    
    l.append(((xA-x2)**2 + (y1-yB)**2)**0.5 + abs(x1-xA) + abs(y2-yB))
    #print(l[-1])
    #print(l)
    print(min(l))
    
    '''
    1 1 -3
    0 3 3 0
    
    3 1 -9
    0 3 3 -1
    '''


import math
a,b,c=list(map(int,input().split()))
x1,y1,x2,y2=list(map(int,input().split()))
s=abs(x1-x2)+abs(y1-y2)
if a!=0:
    xk1=-1*(b*y1+c)/a
    xk2=-1*(b*y2+c)/a
else:
    xk1=10**18
    xk2=10**18
if b!=0:
    yk1=-1*(a*x1+c)/b
    yk2=-1*(a*x2+c)/b
else:
    yk1=10**18
    yk2=10**18
lx1=abs(y1-yk1)
lx2=abs(y2-yk2)
ly1=abs(x1-xk1)
ly2=abs(x2-xk2)
s1=math.sqrt((x1-x2)**2+(yk1-yk2)**2)
s2=math.sqrt((x1-xk1)**2+(yk1-y1)**2)
s3=math.sqrt((x1-xk2)**2+(yk1-y2)**2)
s4=math.sqrt((xk1-x2)**2+(y1-yk2)**2)
s5=math.sqrt((x2-xk2)**2+(y2-yk2)**2)
s6=math.sqrt((xk1-xk2)**2+(y1-y2)**2)
s=min(s,lx1+lx2+s1,lx1+s3+ly2,ly1+s4+lx2,ly1+s6+ly2)
print(s)


a, b, c = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())
p = []
if b != 0:
    p.append((x1, -(a * x1 + c) / b))
    p.append((x2, -(a * x2 + c) / b))
if a != 0:
    p.append((-(b * y1 + c) / a, y1))
    p.append((-(b * y2 + c) / a, y2))
p2 = []
for x, y in p:
    if min(x1, x2) - 0.0001 < x < max(x1, x2) + 0.0001 and min(y1, y2) - 0.0001 < y < max(y1, y2) + 0.0001:
        p2.append((x, y))
p3 = []
for x0, y0 in p2:
    for x, y in p3:
        if max(abs(x - x0), abs(y - y0)) < 0.0001:
            break
    else:
        p3.append((x0, y0))
if len(p3) < 2:
    print(abs(x1 - x2) + abs(y1 - y2))
else:
    r0 = abs(x1 - x2) + abs(y1 - y2)
    (ax, ay), (bx, by) = p3
    d = ((ax - bx) ** 2 + (ay - by) ** 2) ** 0.5
    r1 = abs(x1 - ax) + abs(y1 - ay) + d + abs(bx - x2) + abs(by - y2)
    r2 = abs(x1 - bx) + abs(y1 - by) + d + abs(ax - x2) + abs(ay - y2)
    print(min(r0, r1, r2))

import math

a,b,c = [float(i) for i in input().split()]
xy = [float(i) for i in input().split()]
A =[xy[0],xy[1]]
B =[xy[2],xy[3]]

distances = []

def get_distance(K, M):
    return math.sqrt((K[0]-M[0])*(K[0]-M[0]) + (K[1]- M[1])*(K[1] - M[1]))

def get_point_h(K):
    x = (-b*K[1]-c) / a
    point = (x, K[1])
    distance = get_distance(K, point)
    return point, distance
    
def get_point_v(K):
    y = (-a*K[0]-c) / b
    point = (K[0], y)
    distance = get_distance(K, point)
    return point, distance


manhatten_distance = abs(A[0] - B[0]) + abs(A[1] - B[1])
#print(manhatten_distance)

distances.append(manhatten_distance)

if a != 0:
    p1, d1 = get_point_h(A)
    p3, d3 = get_point_h(B)
    distances.append(get_distance(p1, p3) + d1 + d3)

if b != 0:
    p2, d2 = get_point_v(A)
    p4, d4 = get_point_v(B)
    distances.append(get_distance(p2, p4) + d2 + d4)

if a != 0 and b != 0:
    distances.append(get_distance(p2, p3) + d2 + d3)
    distances.append(get_distance(p1, p4) + d1 + d4)

#print(distances)
print(min(distances))


from math import sqrt

def sqr(a):
        return a * a

a, b, c = [float(i) for i in input().split()]
x1, y1, x2, y2 = [float(i) for i in input().split()]

if a == 0 or b == 0:
        print(abs(x1 - x2) + abs(y1 - y2))
        return

c1_y = -(a * x1 + c) / b
c2_y = -(a * x2 + c) / b
c1_x = -(b * y1 + c) / a
c2_x = -(b * y2 + c) / a

ans = abs(x1 - x2) + abs(y1 - y2)

now = abs(c1_y - y1) + sqrt(sqr(x1 - c2_x) + sqr(c1_y - y2)) + abs(c2_x - x2);
ans = min(ans, now);

now = abs(c1_y - y1) + sqrt(sqr(x1 - x2) + sqr(c1_y - c2_y)) + abs(c2_y - y2);
ans = min(ans, now);

now = abs(c1_x - x1) + sqrt(sqr(c1_x - c2_x) + sqr(y1 - y2)) + abs(c2_x - x2);
ans = min(ans, now);

now = abs(c1_x - x1) + sqrt(sqr(c1_x - x2) + sqr(y1 - c2_y)) + abs(c2_y - y2);
ans = min(ans, now);

print("%.30f" % ans)


import math
s = input().split()
a = int(s[0])
b = int(s[1])
c = int(s[2])
s = input().split()
x1 = int(s[0])
y1 = int(s[1])
x2 = int(s[2])
y2 = int(s[3])

if (x1 == x2):
    print(abs(y1 - y2))
elif (y1 == y2):
    print(abs(x1 - x2))
else:
    if (a != 0 and b != 0):
        var1 = abs(x1 - x2) + abs(y1 - y2)
    
        var2 = 0
        x = x1
        y = (a * x + c) / b * (-1)
        var2 += abs(y1 - y)
        x3 = x2
        y3 = (a * x3 + c) / b * (-1)
        var2 += math.sqrt((x - x3) ** 2 + (y - y3) ** 2)
        var2 += abs(y3 - y2)
    
        var3 = 0
        x = x1
        y = (a * x + c) / b * (-1)
        var3 += abs(y1 - y)
        y3 = y2
        x3 = (b * y3 + c) / a * (-1)
        var3 += math.sqrt((x - x3) ** 2 + (y - y3) ** 2)
        var3 += abs(x3 - x2)
    
        var4 = 0
        y = y1
        x = (b * y + c) / a * (-1)
        var4 += abs(x1 - x)
        y3 = y2
        x3 = (b * y3 + c) / a * (-1)
        var4 += math.sqrt((x - x3) ** 2 + (y - y3) ** 2)
        var4 += abs(x3 - x2)
    
        var5 = 0
        y = y1
        x = (b * y + c) / a * (-1)
        var5 += abs(x1 - x)
        x3 = x2
        y3 = (a * x3 + c) / b * (-1)
        var5 += math.sqrt((x - x3) ** 2 + (y - y3) ** 2)
        var5 += abs(y3 - y2)
    
        print(min(var1, var2, var3, var4, var5))
    else:
        print(abs(x1 - x2) + abs(y1 - y2))

from math import *


a, b, c = list(map(int, input().split()))
x1, y1, x2, y2 = list(map(int, input().split()))
m = -1
if a == 0 or b == 0:
    print(abs(x2 - x1) + abs(y2 - y1))
else:
    tr = [[[x1, ((a * x1 + c) / -b)], [((b * y1 + c) / -a), y1]],
          [[x2, ((a * x2 + c) / -b)], [((b * y2 + c) / -a), y2]]]

    for i in range(2):
        for j in range(2):
            sqr = sqrt((tr[0][i][0] - tr[1][j][0])*(tr[0][i][0] - tr[1][j][0]) + (tr[0][i][1] - tr[1][j][1])*(tr[0][i][1] - tr[1][j][1]))
            if m == -1:
                m = abs(x1 - tr[0][i][0]) + abs(y1 - tr[0][i][1]) + abs(x2 - tr[1][j][0]) + abs(y2 - tr[1][j][1]) + sqr
            else:
                m = min(abs(x1 - tr[0][i][0]) + abs(y1 - tr[0][i][1]) + abs(x2 - tr[1][j][0]) + abs(y2 - tr[1][j][1]) + sqr, m)
    print(min(m, abs(x2 - x1) + abs(y2 - y1)))


import math
a, b, c = [int(i) for i in input().split()]
x1, y1, x2, y2 = [int(i) for i in input().split()]
l1 = abs(x1-x2) + abs(y1-y2)
if(a == 0 or b == 0):
    print(l1)
    return
xa = -(b*y1+c)/a
ya = y1
xb = x1
yb = -(a*x1+c)/b
xc = -(b*y2+c)/a
yc = y2
xd = x2
yd = -(a*x2+c)/b
l2 = abs(x1-xa) + math.sqrt((xa-xc)**2 + (ya-yc)**2)+abs(xc-x2)
l3 = abs(x1-xa) + math.sqrt((xa-xd)**2 + (ya-yd)**2)+abs(yd-y2)
l4 = abs(y1-yb) + math.sqrt((xb-xc)**2 + (yb-yc)**2) + abs(xc-x2)
l5 = abs(y1-yb) + math.sqrt((xb-xd)**2 + (yb-yd)**2) + abs(yd-y2)
print(min(l1, l2, l3, l4, l5))

import math

def lll(a, b):
  return math.sqrt((b[0] - a[0])**2 + (b[1] - a[1])**2)
def III(a, b):
  return abs(b[0] - a[0]) + abs(b[1] - a[1])

a, b, c = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())

g = [[]] * 8
for i in range(8):
  g[i] = [float('inf')] * 8

p = [
  (x1, y1),
  (x1, y2),
  (x2, y2),
  (x2, y1),
]

l = []
if a != 0 and b != 0:
  l = [
    (x1, (-a*x1 - c) / b),
    ((-b*y1 - c) / a, y1),
    (x2, (-a*x2 - c) / b),
    ((-b*y2 - c) / a, y2),
  ]
else:
  l = [
    (x1, y1),
    (x1, y1),
    (x1, y1),
    (x1, y1),
  ]
for i in range(4):
  for j in range(4):
    g[i][4 + j] = g[4 + j][i] = III(p[i], l[j])
    if (i != j):
      g[i][j] = g[j][i] = III(p[i], p[j])
      g[4 + i][4 + j] = g[4 + j][4 + i] = lll(l[i], l[j])

ls = [float('inf')] * 8
ls[0] = 0
qu = [0]
while len(qu) > 0:
  i = qu[0]
  qu = qu[1:]
  for j in range(8):
    if ls[i] + g[i][j] < ls[j]:
      ls[j] = ls[i] + g[i][j]
      if not j in qu:
        qu += [j]
print(ls[2]) 

a,b,c=list(map(int,input().split()))
x1,y1,x2,y2=list(map(int,input().split()))
bRange=abs(y2-y1)+abs(x2-x1)
if a==0 or b==0:
    print(bRange)
else:
    py1=(-b*y1-c)/a
    py2=(-b*y2-c)/a
    px1=(-a*x1-c)/b
    px2=(-a*x2-c)/b
    pRange1=((x2-py1)**2+(px2-y1)**2)**0.5+abs(y2-px2)+abs(py1-x1)
    pRange2=((py2-py1)**2+(y2-y1)**2)**0.5+abs(py1-x1)+abs(x2-py2)
    pRange3=((x2-x1)**2+(px2-px1)**2)**0.5+abs(px1-y1)+abs(y2-px2)
    pRange4=((py2-x1)**2+(y2-px1)**2)**0.5+abs(px1-y1)+abs(x2-py2)
    print(min(bRange,pRange1,pRange2,pRange3,pRange4))


import math

def rst(A,B):
    x1 = A[0]
    y1 = A[1]
    x2 = B[0]
    y2 = B[1]
    
    return math.sqrt((x1-x2)**2 + (y1-y2)**2)

a,b,c = list(map(float,input().split()))
x1,y1,x2,y2 = list(map(float,input().split()))

l = []

if a == 0 or b == 0:
    print(abs(x2-x1)+abs(y1-y2))
else:
    st = (x1,y1)
    fn = (x2,y2)
    
    xa = x1
    ya = (-c - a*x1) / b
    A = (xa,ya)
    
    xb = x2
    yb = (-c - a*x2) / b
    B = (xb,yb)
    
    xc = (-c - b*y1)/a
    yc = y1
    C = (xc,yc)
    
    xd = (-c - b*y2)/a
    yd = y2
    
    D = (xd,yd)
    
    print(min(abs(x2-x1)+abs(y1-y2),rst(st,A) + rst(A,B) + rst(B,fn),rst(st,A) + rst(A,D) + rst(D,fn),rst(st,C) + rst(C,B) + rst(B,fn),rst(st,C) + rst(C,D) + rst(D,fn)))


a, b, c = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())
if a != 0 and b != 0:
    x1_ = ((-1) * (b * y1 + c)) / a
    y1_ = ((-1) * (a * x1 + c)) / b
    x2_ = ((-1) * (b * y2 + c)) / a
    y2_ = ((-1) * (a * x2 + c)) / b
    p1 = abs(x1 - x1_) + abs(y2 - y2_) + ((x1_ - x2) ** 2 + (y1 - y2_) ** 2) ** 0.5
    p2 = abs(x1 - x1_) + abs(x2 - x2_) + ((x1_ - x2_) ** 2 + (y1 - y2) ** 2) ** 0.5
    p3 = abs(y1 - y1_) + abs(y2 - y2_) + ((x1 - x2) ** 2 + (y1_ - y2_) ** 2) ** 0.5
    p4 = abs(y1 - y1_) + abs(x2 - x2_) + ((x1 - x2_) ** 2 + (y1_ - y2) ** 2) ** 0.5
    p5 = abs(y1 - y2) + abs(x2 - x1)
    sp = [p1, p2, p3, p4, p5]
    print(min(sp))
else:
    print(abs(y1 - y2) + abs(x2 - x1))

from math import sqrt
a, b, c = list(map(float, input().split()))
x1, y1, x2, y2 = list(map(float, input().split()))

def main():
    nonlocal a, b, c, x1, y1, x2, y2
    if (b==0 or a==0):
        return (abs(x1-x2)+abs(y1-y2))

    AD, AC, DB, CB = False, False, False, False
    y = lambda x0: -c/b -a/b*x0
    x = lambda y0: -c/a -b/a*y0
    r = lambda x1, y1, x2, y2 : sqrt((x1-x2)**2 + (y1-y2)**2)
    yes = lambda x1, x, x2: (min(x1, x2) <= x and x <= max(x1, x2))

    '''print(x(y1), x(y2), y(x1), y(x2))'''
    if (yes(y1, y(x1), y2) and yes(y1, y(x2), y2)):
        '''print(1)'''
        e = abs(y(x1) - y1)
        f = abs(y(x2) - y2)
        g = r(x1, y(x1), x2, y(x2))
        '''print(e, f, g)'''
        return (e+f+g)
    
    if (yes(y1, y(x1), y2) and yes(x1, x(y2), x2)):
        '''print(2)'''
        e = abs(y(x1) - y1)
        f = abs(x(y2) - x2)
        g = r(x1, y(x1), x(y2), y2)
        '''print(e, f, g)'''
        return (e+f+g)
        
    if (yes(x1, x(y1), x2) and yes(x1, x(y2), x2)):
        '''print(3)'''
        e = abs(x(y1) - x1)
        f = abs(x(y2) - x2)
        g = r(x(y1), y1, x(y2), y2)
        '''print(e, f, g)'''
        return (e+f+g)

    if (yes(x1, x(y1), x2) and yes(y1, y(x2), y2)):
        '''print(4)'''
        e = abs(x(y1) - x1)
        f = abs(y(x2) - y2)
        g = r(x(y1), y1, x2, y(x2))
        '''print(e, f, g)'''
        return (e+f+g)

    '''print("none returned!")'''
    return (abs(x1-x2)+abs(y1-y2))

ans = main()
straight = abs(x1-x2) + abs(y1-y2)
print(min(ans, straight))


#!/usr/bin/env python3

from fractions import Fraction
from math import sqrt

def gety(a, b, c, x):
    return -Fraction(a * x + c, b)

def getx(a, b, c, y):
    return -Fraction(b * y + c, a)

def ds(x1, y1, x2, y2):
    return sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)

a, b, c = list(map(int, input().split()))
x1, y1, x2, y2 = list(map(int, input().split()))

silly_dist = abs(x1 - x2) + abs(y1 - y2)
if a == 0 or b == 0:
    print(silly_dist)
    return

dq = silly_dist

mx = x1
my = gety(a, b, c, mx)
ny = y1
nx = getx(a, b, c, ny)

kx = x2
ky = gety(a, b, c, kx)
ty = y2
tx = getx(a, b, c, ty)

dq1 = ds(mx, my, kx, ky) + ds(mx, my, x1, y1) + ds(kx, ky, x2, y2)
dq2 = ds(nx, ny, kx, ky) + ds(nx, ny, x1, y1) + ds(kx, ky, x2, y2)
dq3 = ds(mx, my, tx, ty) + ds(mx, my, x1, y1) + ds(tx, ty, x2, y2)
dq4 = ds(nx, ny, tx, ty) + ds(nx, ny, x1, y1) + ds(tx, ty, x2, y2)

#print([dq, dq1, dq2, dq3, dq4])
dqmin = min([dq, dq1, dq2, dq3, dq4])
print(dqmin)


def dst1(x1, x2, y1, y2):
    return abs(x1 - x2) + abs(y1 - y2)

def dst2(x1, x2, y1, y2):
    return ((x1 - x2)**2 + (y1 - y2)**2)**0.5

def getx(y):
    return (-b*y-c)/a

def gety(x):
    return (-a*x-c)/b

a, b, c = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())

def sign(a):
    if a > 0:
        return 1
    elif a == 0:
        return 0
    else:
        return -1
    
if a == 0 or b == 0:
    print(dst1(x1, x2, y1, y2))
else:
    s1 = dst1(x1, x2, y1, y2)
    
    
    p1x = x1
    p1y = gety(p1x)
    p3y = y1
    p3x = getx(p3y)
    
    p2x = x2
    p2y = gety(p2x)
    p4y = y2
    p4x = getx(p4y)
    
    
    
    s = 0
    s += dst1(x1, p1x, y1, p1y)
    s += dst2(p1x, p2x, p1y, p2y)
    s += dst1(p2x, x2, p2y, y2)
    s2 = s
    
    s = 0
    s += dst1(x1, p3x, y1, p3y)
    s += dst2(p3x, p2x, p3y, p2y)
    s += dst1(p2x, x2, p2y, y2)
    s3 = s
    
    s = 0
    s += dst1(x1, p1x, y1, p1y)
    s += dst2(p1x, p4x, p1y, p4y)
    s += dst1(p4x, x2, p4y, y2)
    s4 = s
    
    s = 0
    s += dst1(x1, p3x, y1, p3y)
    s += dst2(p3x, p4x, p3y, p4y)
    s += dst1(p4x, x2, p4y, y2)
    s5 = s
    
    print(min(s1, s2, s3, s4, s5))

from math import sqrt

a, b, c = list(map(int, input().split()))
x1, y1, x2, y2 = list(map(int, input().split()))
res1 = abs(x1 - x2) + abs(y1 - y2)

res2 = 10 ** 10 + 7
res3 = 10 ** 10 + 7
res4 = 10 ** 10 + 7
res5 = 10 ** 10 + 7

if b != 0 and a != 0:
    x = (-y1 * b - c) / a
    y = (-x2 * a - c) / b
    res2 = abs(x1 - x) + abs(y2 - y) + sqrt(abs(x - x2) ** 2 + abs(y1 - y) ** 2)

if a != 0:
    x = (-y1 * b - c) / a
    xx = (-y2 * b - c) / a
    res4 = abs(x1 - x) + abs(x2 - xx) + sqrt(abs(x - xx) ** 2 + abs(y1 - y2) ** 2)

if b != 0:
    y = (-x1 * a - c) / b
    yy = (-x2 * a - c) / b
    res5 = abs(y1 - y) + abs(y2 - yy) + sqrt(abs(y - yy) ** 2 + abs(x1 - x2) ** 2)

if a != 0 and b != 0:
    x = (-y2 * b - c) / a
    y = (-x1 * a - c) / b
    res3 = abs(y1 - y) + abs(x2 - x) + sqrt(abs(x1 - x) ** 2 + abs(y2 - y) ** 2)

print(min(res1, res2, res3, res4, res5))
# print(res1, res2, res3, res4, res5)


import math
a, b, c = list(map(int, input().split()))
ax, ay, bx, by = list(map(int, input().split()))
if (a==0 or b==0):
    print(abs(ax - bx) + abs(ay - by))
    return
oy = -(a*ax+c)/b
ty = -(a*bx+c)/b
ox = -(b*ay+c)/a
tx = -(b*by+c)/a
ans = abs(ax - bx) + abs(ay - by)
ans1 = abs(ay - oy) + abs(by - ty) + math.sqrt(abs(ax - bx)**2 + abs(oy - ty)**2)
ans2 = abs(ax - ox) + abs(bx - tx) + math.sqrt(abs(ay - by)**2 + abs(ox - tx)**2)
ans3 = abs(ax - ox) + abs(by - ty) + math.sqrt(abs(bx - ox)**2 + abs(ay - ty)**2)
ans4 = abs(ay - oy) + abs(bx - tx) + math.sqrt(abs(by - oy)**2 + abs(ax - tx)**2)
print(min(ans, ans1, ans2, ans3, ans4))


from math import *
a, b, c = list(map(int, input().split()))
x1, y1, x2, y2 = list(map(int, input().split()))
d = abs(x1 - x2) + abs(y1 - y2)
if a != 0 and b != 0:
    dy1 = abs(x1 + (c + b * y1) / a)
    dx1 = abs(y1 + (c + a * x1) / b)
    yy1 = y1
    xy1 = -(c + b * y1) / a
    xx1 = x1
    yx1 = -(c + a * x1) / b
    dy2 = abs(x2 + (c + b * y2) / a)
    dx2 = abs(y2 + (c + a * x2) / b)
    yy2 = y2
    xy2 = -(c + b * y2) / a
    xx2 = x2
    yx2 = -(c + a * x2) / b
    d1 = dy1 + dy2 + sqrt((xy1 - xy2)**2 + (yy1 - yy2)**2)
    d2 = dx1 + dx2 + sqrt((xx1 - xx2)**2 + (yx1 - yx2)**2)
    d3 = dy1 + dx2 + sqrt((xy1 - xx2)**2 + (yy1 - yx2)**2)
    d4 = dx1 + dy2 + sqrt((xx1 - xy2)**2 + (yx1 - yy2)**2)
    print(min(d, d1, d2, d3, d4))
else:
    print(d)


from math import *

def r(x1, y1, x2, y2):
    return (abs(x1 - x2) ** 2 + abs(y1 - y2) ** 2) ** 0.5

a, b, c = map(int,input().split())
x1, y1, x2, y2 = map(int,input().split())
r1 = abs(x1 - x2) + abs(y1 - y2)
if (a == 0 or b == 0):
    print(r1)
else:
    k = - a / b
    b = - c / b
    x01 = x1
    y01 = k * x1 + b
    x02 = (y2 - b) / k
    y02 = y2
    x03 = x2
    y03 = k * x2 + b
    x04 = (y1 - b) / k
    y04 = y1
    r2 = r(x1, y1, x01, y01) + r(x01, y01, x02, y02) + r(x02, y02, x2, y2)
    r3 = r(x1, y1, x01, y01) + r(x01, y01, x03, y03) + r(x03, y03, x2, y2)

    r12 = r(x1, y1, x04, y04) + r(x04, y04, x02, y02) + r(x02, y02, x2, y2)
    r13 = r(x1, y1, x04, y04) + r(x04, y04, x03, y03) + r(x03, y03, x2, y2)

    print(min(r1, r2, r3, r12, r13))

from math import sqrt


def ro(x, y):
    return sqrt((x[0] - y[0])**2 + (x[1] - y[1])**2)


a, b, c = list(map(int, input().split()))
A = [0, 0]
B = [0, 0]
A[0], A[1], B[0], B[1] = list(map(int, input().split()))
if a == 0 or b == 0:
    #print(1)
    print(float(abs(A[0] - B[0]) + abs(A[1] - B[1])))
elif ((-a*A[0] - c) / b > max(A[1], B[1]) and (-a*B[0] - c) / b > max(A[1], B[1])) or ((-a*A[0] - c) / b < min(A[1], B[1]) and (-a*B[0] - c) / b < min(A[1], B[1])):
    #print(2)
    print(float(abs(A[0] - B[0]) + abs(A[1] - B[1])))
elif ((B[0] - A[0]) / (B[1] - A[1])) * (-a / b) <= 0:
    #print(3)
    print(float(abs(A[0] - B[0]) + abs(A[1] - B[1])))
else:
    ab = False
    bb = False
    cb = False
    db = False
    C = [0, 0]
    D = [0, 0]
    if min(A[1], B[1]) <= (-a*min(A[0], B[0]) - c) / b <= max(A[1], B[1]):
        ab = True
    if min(A[1], B[1]) <= (-a*max(A[0], B[0]) - c) / b <= max(A[1], B[1]):
        cb = True
    if min(A[0], B[0]) < (-b*max(A[1], B[1]) - c) / a < max(A[0], B[0]):
        bb = True
    if min(A[0], B[0]) < (-b*min(A[1], B[1]) - c) / a < max(A[0], B[0]):
        db = True
    k = -a/b
    r = abs(A[0] - B[0]) + abs(A[1] - B[1])
    if ab and bb:
        C[0] = min(A[0], B[0])
        C[1] = (-a*min(A[0], B[0]) - c) / b
        D[0] = (-b*max(A[1], B[1]) - c) / a
        D[1] = max(A[1], B[1])
        r = abs(C[1] - min(A[1], B[1])) + abs(max(A[0], B[0]) - D[0]) + ro(C, D)
    if ab and cb:
        C[0] = min(A[0], B[0])
        C[1] = (-a*min(A[0], B[0]) - c) / b
        D[0] = max(A[0], B[0])
        D[1] = (-a*max(A[0], B[0]) - c) / b
        if C[1] < D[1]:
            r = abs(C[1] - min(A[1], B[1])) + abs(max(A[1], B[1]) - D[1]) + ro(C, D)
        else:
            r = abs(D[1] - min(A[1], B[1])) + abs(max(A[1], B[1]) - C[1]) + ro(C, D)
    if ab and db:
        C[0] = min(A[0], B[0])
        C[1] = (-a*min(A[0], B[0]) - c) / b
        D[0] = (-b*min(A[1], B[1]) - c) / a
        D[1] = min(A[1], B[1])
        r = abs(max(A[1], B[1]) - C[1]) + abs(max(A[0], B[0]) - D[0]) + ro(C, D)
    if bb and cb:
        C[0] = (-b * max(A[1], B[1]) - c) / a
        C[1] = max(A[1], B[1])
        D[0] = max(A[0], B[0])
        D[1] = (-a * max(A[0], B[0]) - c) / b
        r = abs(C[0] - min(A[0], B[0])) + abs(D[1] - min(A[1], B[1])) + ro(C, D)
    if bb and db:
        C[0] = (-b * max(A[1], B[1]) - c) / a
        C[1] = max(A[1], B[1])
        D[0] = (-b * min(A[1], B[1]) - c) / a
        D[1] = min(A[1], B[1])
        if C[0] > D[0]:
            r = abs(D[0] - min(A[0], B[0])) + abs(max(A[0], B[0]) - C[0]) + ro(C, D)
        else:
            r = abs(C[0] - min(A[0], B[0])) + abs(max(A[0], B[0]) - D[0]) + ro(C, D)
    if cb and db:
        C[0] = max(A[0], B[0])
        C[1] = (-a * max(A[0], B[0]) - c) / b
        D[0] = (-b * min(A[1], B[1]) - c) / a
        D[1] = min(A[1], B[1])
        r = abs(D[0] - min(A[0], B[0])) + abs(max(A[1], B[1]) - C[1]) + ro(C, D)
    print(r)


from math import sqrt


def ro(x, y):
    return sqrt((x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2)


def make_y(k):
    return (-a * k - c) / b


def make_x(k):
    return (-b * k - c) / a


a, b, c = list(map(int, input().split()))
A = [0, 0]
B = [0, 0]
A[0], A[1], B[0], B[1] = list(map(int, input().split()))
if a == 0 or b == 0:
    print(abs(A[0] - B[0]) + abs(A[1] - B[1]))
else:
    ans = [abs(A[0] - B[0]) + abs(A[1] - B[1]),
           abs(make_y(A[0]) - A[1]) + abs(make_y(B[0]) - B[1]) + ro([A[0], make_y(A[0])], [B[0], make_y(B[0])]),
           abs(make_x(A[1]) - A[0]) + abs(make_y(B[0]) - B[1]) + ro([make_x(A[1]), A[1]], [B[0], make_y(B[0])]),
           abs(make_y(A[0]) - A[1]) + abs(make_x(B[1]) - B[0]) + ro([A[0], make_y(A[0])], [make_x(B[1]), B[1]]),
           abs(make_x(A[1]) - A[0]) + abs(make_x(B[1]) - B[0]) + ro([make_x(A[1]), A[1]], [make_x(B[1]), B[1]])]
    print(min(ans))