It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin.

We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (x_{i}, y_{i}). Both Adil and Bera can carry only one bottle at once each. 

For both Adil and Bera the process looks as follows:   Choose to stop or to continue to collect bottles.  If the choice was to continue then choose some bottle and walk towards it.  Pick this bottle and walk to the recycling bin.  Go to step 1. 

Adil and Bera may move independently. They are allowed to pick bottles simultaneously, all bottles may be picked by any of the two, it's allowed that one of them stays still while the other one continues to pick bottles.

They want to organize the process such that the total distance they walk (the sum of distance walked by Adil and distance walked by Bera) is minimum possible. Of course, at the end all bottles should lie in the recycling bin.


-----Input-----

First line of the input contains six integers a_{x}, a_{y}, b_{x}, b_{y}, t_{x} and t_{y} (0 ≤ a_{x}, a_{y}, b_{x}, b_{y}, t_{x}, t_{y} ≤ 10^9) — initial positions of Adil, Bera and recycling bin respectively.

The second line contains a single integer n (1 ≤ n ≤ 100 000) — the number of bottles on the ground.

Then follow n lines, each of them contains two integers x_{i} and y_{i} (0 ≤ x_{i}, y_{i} ≤ 10^9) — position of the i-th bottle.

It's guaranteed that positions of Adil, Bera, recycling bin and all bottles are distinct.


-----Output-----

Print one real number — the minimum possible total distance Adil and Bera need to walk in order to put all bottles into recycling bin. Your answer will be considered correct if its absolute or relative error does not exceed 10^{ - 6}.

Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct if $\frac{|a - b|}{\operatorname{max}(1, b)} \leq 10^{-6}$.


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

Output
11.084259940083

Input
5 0 4 2 2 0
5
5 2
3 0
5 5
3 5
3 3

Output
33.121375178000



-----Note-----

Consider the first sample.

Adil will use the following path: $(3,1) \rightarrow(2,1) \rightarrow(0,0) \rightarrow(1,1) \rightarrow(0,0)$.

Bera will use the following path: $(1,2) \rightarrow(2,3) \rightarrow(0,0)$.

Adil's path will be $1 + \sqrt{5} + \sqrt{2} + \sqrt{2}$ units long, while Bera's path will be $\sqrt{2} + \sqrt{13}$ units long.

Difficulty: competition

Starter code:

Solutions:
from math import *

ax, ay, bx, by, cx, cy = [int(t) for t in input().split()]
n = int(input())
dist = 0
maxv = [[-inf, -inf], [-inf, -inf]]
index = [[0,0], [0,0]]

def update(d, idx, p):
    nonlocal maxv, index
    if d > maxv[p][0]:
        maxv[p][1] = maxv[p][0]
        index[p][1] = index[p][0]
        maxv[p][0] = d
        index[p][0] = idx
    elif d > maxv[p][1]:
        maxv[p][1] = d
        index[p][1] = idx

for i in range(n):
    x, y = [int(t) for t in input().split()]
    bottle_recycle = sqrt((cx - x) ** 2 + (cy - y) ** 2)
    dist += bottle_recycle * 2
    dista = bottle_recycle - sqrt((ax - x) ** 2 + (ay - y) ** 2)
    distb = bottle_recycle - sqrt((bx - x) ** 2 + (by - y) ** 2)
    update(dista, i, 0)
    update(distb, i, 1)

ans = dist - maxv[0][0]
ans = min(ans, dist - maxv[1][0])
if(index[0][0] != index[1][0]):
    ans = min(ans, dist - maxv[0][0] - maxv[1][0])
elif(n > 1):
    ans = min(ans, dist - maxv[0][1] - maxv[1][0], dist - maxv[0][0] - maxv[1][1])
print(ans)

from math import *

ax, ay, bx, by, cx, cy = map(lambda t: int(t), input().split())
n = int(input())
dist = 0
maxv = [[-inf, -inf], [-inf, -inf]]
index = [[0,0], [0,0]]

def update(d, idx, p):
    nonlocal maxv, index
    if d > maxv[p][0]:
        maxv[p][1] = maxv[p][0]
        index[p][1] = index[p][0]
        maxv[p][0] = d
        index[p][0] = idx
    elif d > maxv[p][1]:
        maxv[p][1] = d
        index[p][1] = idx

for i in range(n):
    x, y = map(lambda t: int(t), input().split())
    bottle_recycle = sqrt((cx - x) ** 2 + (cy - y) ** 2)
    dist += bottle_recycle * 2
    dista = bottle_recycle - sqrt((ax - x) ** 2 + (ay - y) ** 2)
    distb = bottle_recycle - sqrt((bx - x) ** 2 + (by - y) ** 2)
    update(dista, i, 0)
    update(distb, i, 1)

ans = dist - maxv[0][0]
ans = min(ans, dist - maxv[1][0])
if(index[0][0] != index[1][0]):
    ans = min(ans, dist - maxv[0][0] - maxv[1][0])
elif(n > 1):
    ans = min(ans, dist - maxv[0][1] - maxv[1][0], dist - maxv[0][0] - maxv[1][1])
print(ans)

def main():
    from math import hypot
    from sys import stdin
    ax, ay, bx, by, tx, ty = list(map(float, input().split()))
    n, tot = int(input()), 0.
    m0 = m1 = m2 = m3 = -9e9
    j = k = 0
    for i, s in enumerate(stdin.read().splitlines()):
        x, y = list(map(float, s.split()))
        r = hypot(tx - x, ty - y)
        tot += r
        d = r - hypot(ax - x, ay - y)
        if m1 < d:
            if m0 < d:
                m0, m1, j = d, m0, i
            else:
                m1 = d
        d = r - hypot(bx - x, by - y)
        if m3 < d:
            if m2 < d:
                m2, m3, k = d, m2, i
            else:
                m3 = d
    print(tot * 2. - max((m0, m2) if min(m0, m2) < 0. else((m0 + m2) * (j != k), m0 + m3, m1 + m2, m0, m2)))


def __starting_point():
    main()

__starting_point()

def main():
    from math import hypot
    from sys import stdin
    ax, ay, bx, by, tx, ty = list(map(float, input().split()))
    s, tot = input(), 0.
    m0 = m1 = m2 = m3 = -9e9
    j = k = 0
    for i, s in enumerate(stdin.read().splitlines()):
        x, y = list(map(float, s.split()))
        r = hypot(tx - x, ty - y)
        tot += r
        d = r - hypot(ax - x, ay - y)
        if m1 < d:
            if m0 < d:
                m0, m1, j = d, m0, i
            else:
                m1 = d
        d = r - hypot(bx - x, by - y)
        if m3 < d:
            if m2 < d:
                m2, m3, k = d, m2, i
            else:
                m3 = d
    print(tot * 2. - max((m0, m2, m0 + m2) if j != k else (m0, m2, m0 + m3, m1 + m2)))


def __starting_point():
    main()

__starting_point()

from math import hypot

ax, ay, bx, by, tx, ty = map(int, input().split())

n = int(input())

ans = 0

p1, p2, beg, end = [0]*n, [0]*n, [0]*n, [0]*n

def pref(x):
    return beg[x] if x >= 0 else 0

def suff(x):
    return end[x] if x < n else 0

def ex(x):
    return max(pref(x-1), suff(x+1))

for i in range(n):
    x, y = map(int, input().split())
    d = hypot(x-tx, y-ty)
    d1 = hypot(x-ax, y-ay)
    d2 = hypot(x-bx, y-by)
    ans += d+d
    p1[i], p2[i] = d-d1, d-d2

beg[0] = p1[0]
for i in range(1, n):
    beg[i] = max(beg[i-1], p1[i])

end[n-1] = p1[n-1]
for i in range(n-2, -1, -1):
    end[i] = max(end[i+1], p1[i])

res = 1e220

for i in range(0, n):
    res = min(res, min(ans-p2[i]-ex(i), ans-max(p1[i], p2[i])))

print(res)

from math import hypot

ax, ay, bx, by, tx, ty = map(int, input().split())

n = int(input())

ans = 0

p1, p2, beg, end = [0]*n, [0]*n, [0]*n, [0]*n

def pref(x):
    return beg[x] if x >= 0 else 0

def suff(x):
    return end[x] if x < n else 0

def ex(x):
    return max(pref(x-1), suff(x+1))

for i in range(n):
    x, y = map(int, input().split())
    d = hypot(x-tx, y-ty)
    d1 = hypot(x-ax, y-ay)
    d2 = hypot(x-bx, y-by)
    ans += d+d
    p1[i], p2[i] = d-d1, d-d2

beg[0] = p1[0]
for i in range(1, n):
    beg[i] = max(beg[i-1], p1[i])

end[n-1] = p1[n-1]
for i in range(n-2, -1, -1):
    end[i] = max(end[i+1], p1[i])

res = 1e220

for i in range(0, n):
    res = min(res, min(ans-p2[i]-ex(i), ans-max(p1[i], p2[i])))

print(res)

from math import sqrt

ax, ay, bx, by, tx, ty = map(int, input().split())

n = int(input())

ans = 0

p1, p2, beg, end = [0]*n, [0]*n, [0]*n, [0]*n

def sqr(x):
    return x*x

def pref(x):
    return beg[x] if x >= 0 else 0

def suff(x):
    return end[x] if x < n else 0

def ex(x):
    return max(pref(x-1), suff(x+1))

for i in range(n):
    x, y = map(int, input().split())
    d = sqrt(sqr(x-tx) + sqr(y-ty))
    d1 = sqrt(sqr(x-ax) + sqr(y-ay))
    d2 = sqrt(sqr(x-bx) + sqr(y-by))
    ans += d+d
    p1[i], p2[i] = d-d1, d-d2

beg[0] = p1[0]
for i in range(1, n):
    beg[i] = max(beg[i-1], p1[i])

end[n-1] = p1[n-1]
for i in range(n-2, -1, -1):
    end[i] = max(end[i+1], p1[i])

res = 1e220

for i in range(0, n):
    res = min(res, min(ans-p2[i]-ex(i), ans-max(p1[i], p2[i])))

print(res)

from math import sqrt

ax, ay, bx, by, tx, ty = map(int, input().split())

n = int(input())

ans = 0

p1, p2, beg, end = [0]*n, [0]*n, [0]*n, [0]*n

def sqr(x):
    return x*x

def pref(x):
    return beg[x] if x >= 0 else 0

def suff(x):
    return end[x] if x < n else 0

def ex(x):
    return max(pref(x-1), suff(x+1))

for i in range(n):
    x, y = map(int, input().split())
    d = sqrt(sqr(x-tx) + sqr(y-ty))
    d1 = sqrt(sqr(x-ax) + sqr(y-ay))
    d2 = sqrt(sqr(x-bx) + sqr(y-by))
    ans += d+d
    p1[i], p2[i] = d-d1, d-d2

beg[0] = p1[0]
for i in range(1, n):
    beg[i] = max(beg[i-1], p1[i])

end[n-1] = p1[n-1]
for i in range(n-2, -1, -1):
    end[i] = max(end[i+1], p1[i])

res = 1e220

for i in range(0, n):
    res = min(res, min(ans-p2[i]-ex(i), ans-max(p1[i], p2[i])))

print(res)

import math, sys

ax,ay,bx,by,tx,ty = list(map(float, input().split()))
n = int(input())

def dist(x1,y1,x2,y2):
    return math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2))

cost = 0
bottleCoord = []
for i in range(0,n):
    x,y = list(map(float, input().split()))
    cost += 2*dist(tx,ty,x,y)
    bottleCoord.append((x,y))

asCost = [(0,-1)]
bsCost = [(0,-1)]

for i in range(0,n):
    asCost.append((dist(ax,ay,bottleCoord[i][0],bottleCoord[i][1]) - dist(bottleCoord[i][0],bottleCoord[i][1],tx,ty),i))
    bsCost.append((dist(bx,by,bottleCoord[i][0],bottleCoord[i][1]) - dist(bottleCoord[i][0],bottleCoord[i][1],tx,ty),i))

asCost.sort()
bsCost.sort()
costTmpIndiv = sys.maxsize

for i in range(0,min(len(asCost),5)):
    for j in range(0, min(len(bsCost),5)):
        if (asCost[i][1] != bsCost[j][1]):
            costTmpIndiv = min(costTmpIndiv, asCost[i][0]+bsCost[j][0])

print(cost + costTmpIndiv)


from math import sqrt

ax, ay, bx, by, tx, ty = list(map(int, input().split()))
n = int(input())
d = 0
mina = (2*10**9,0,0)
mina2 = (2*10**9,0,0)
minb = (2*10**9,0,0)
minb2 = (2*10**9,0,0)
for _ in range(n):
  x, y = list(map(int, input().split()))
  dt = sqrt((x-tx)**2+(y-ty)**2)
  d += 2*dt
  da = sqrt((ax-x)**2+(ay-y)**2)
  dat = (da-dt,x,y)
  if dat[0] < mina[0]:
    mina, mina2 = dat, mina
  elif dat[0] < mina2[0]:
    mina2 = dat
  db = sqrt((bx-x)**2+(by-y)**2)
  dbt = (db-dt,x,y)
  if dbt[0] < minb[0]:
    minb, minb2 = dbt, minb
  elif dbt[0] < minb2[0]:
    minb2 = dbt
if n >= 2 and mina[0] < 0 and minb[0] < 0:
  if mina[1] != minb[1] or mina[2] != minb[2]:
    d += mina[0] + minb[0]
  elif mina2[0] < 0 and minb2[0] < 0:
    d += min(mina[0]+minb2[0],mina2[0]+minb[0])
  elif mina2[0] < 0:
    d += min(mina[0],mina2[0]+minb[0])
  elif minb2[0] < 0:
    d += min(mina[0]+minb2[0],minb[0])
  else:
    d += min(mina[0],minb[0])
else:
  d += min(mina[0],minb[0])
print(d)


read = lambda : map(int, input().split())
def dis(x1, y1, x2, y2):
    return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5

ax, ay, bx, by, tx, ty = read()
n = int(input())
a, b = [], []
sum = 0
for i in range(n):
    x, y = read()
    dist = dis(tx, ty, x, y)
    a.append((dis(ax, ay, x, y) - dist, i))
    b.append((dis(bx, by, x, y) - dist, i))
    sum += dist * 2
a.sort()
b.sort()
if n > 1 and a[0][1] == b[0][1]:
    ans = min(a[0][0], b[0][0], a[0][0] + b[1][0], a[1][0] + b[0][0])
else:
    ans = min(a[0][0], b[0][0])
    if (n > 1) :
        ans = min(a[0][0] + b[0][0], ans)
print(ans + sum)

ax,ay,bx,by,tx,ty=list(map(int,input().split()))  #

od=[]  #
co=[] #
objects=int(input())#
for i in range(objects):#
    x,y=list(map(int,input().split()))#
    od.append(((tx-x)**2+(ty-y)**2)**0.5)#
    co.append([x,y])#


asaved=[0,0]#
asaved2=[0,0]#
ma=-(10**25)

for i in range(objects):
    x=co[i][0]
    y=co[i][1]
    saved=od[i]-((ax-x)**2+(ay-y)**2)**0.5
    ma=max(ma,saved)
    if saved>asaved[0]:
        asaved2[0]=asaved[0]
        asaved2[1]=asaved[1]
        asaved[0]=saved
        asaved[1]=i
    elif saved>asaved2[0]:
        asaved2[0]=saved
        asaved2[1]=i


bsaved=[0,0]#
bsaved2=[0,0]#
mb=-(10**25)

for i in range(objects):
    x=co[i][0]
    y=co[i][1]
    saved=od[i]-((bx-x)**2+(by-y)**2)**0.5
    mb=max(mb,saved)
    if saved>bsaved[0]:
        bsaved2[1]=bsaved[1]
        bsaved2[0]=bsaved[0]
        bsaved[0]=saved
        bsaved[1]=i
    elif saved>bsaved2[0]:
        bsaved2[0]=saved
        bsaved2[1]=i


tot=2*sum(od)#
if mb<0 and ma<0:
    tot-=max(mb,ma)
elif bsaved[1]==asaved[1]:
    tot-=max(asaved[0]+bsaved2[0],asaved2[0]+bsaved[0])
else:
    tot-=asaved[0]+bsaved[0]

print(tot)#


read = lambda : list(map(int, input().split()))

def dis(x1, y1, x2, y2):

    return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5



ax, ay, bx, by, tx, ty = read()

n = int(input())

a, b = [], []

sum = 0

for i in range(n):

    x, y = read()

    dist = dis(tx, ty, x, y)

    a.append((dis(ax, ay, x, y) - dist, i))

    b.append((dis(bx, by, x, y) - dist, i))

    sum += dist * 2

a.sort()

b.sort()

if n > 1 and a[0][1] == b[0][1]:

    ans = min(a[0][0], b[0][0], a[0][0] + b[1][0], a[1][0] + b[0][0])

else:

    ans = min(a[0][0], b[0][0])

    if (n > 1) :

        ans = min(a[0][0] + b[0][0], ans)

print(ans + sum)



# Made By Mostafa_Khaled


import math

ax, ay, bx, by, tx, ty = [int(coord) for coord in input().split()]
n = int(input())
x ,y = [], []

minDis = 0
diff1 = []
diff2 = []

for i in range(n):
        xi, yi = [int(coord) for coord in input().split()]
        x.append(xi)
        y.append(yi)
        disBin = math.sqrt((xi-tx)**2 + (yi-ty)**2)
        diff1.append(( math.sqrt((ax-xi)**2 + (ay-yi)**2) - disBin, i))
        diff2.append(( math.sqrt((bx-xi)**2 + (by-yi)**2) - disBin, i))
        minDis += 2 * disBin

diff1.sort()
diff2.sort()

ans = min(minDis + diff1[0][0], minDis + diff2[0][0])

if diff1[0][1] != diff2[0][1]:
        ans = min(ans, minDis + diff1[0][0] + diff2[0][0])

elif n>1:
        ans = min(ans, minDis + diff1[0][0] + diff2[1][0])
        ans = min(ans, minDis + diff1[1][0] + diff2[0][0])

print(ans)

import math
R = lambda: map(int, input().split())
ax, ay, bx, by, tx, ty = R()
n = int(input())
dp = [[0] * (n + 1) for i in range(4)]
for i in range(n):
    x, y = R()
    da, db, dt = ((x - ax) ** 2 + (y - ay) ** 2) ** 0.5, ((x - bx) ** 2 + (y - by) ** 2) ** 0.5, ((x - tx) ** 2 + (y - ty) ** 2) ** 0.5
    dp[0][i] = dp[0][i - 1] + dt * 2
    dp[1][i] = min(dp[0][i - 1] + db + dt, dp[1][i - 1] + dt * 2 if i else math.inf)
    dp[2][i] = min(dp[0][i - 1] + da + dt, dp[2][i - 1] + dt * 2 if i else math.inf)
    dp[3][i] = min(dp[1][i - 1] + da + dt, dp[2][i - 1] + db + dt, dp[3][i - 1] + dt * 2) if i else math.inf
print(min(dp[3][n - 1], dp[2][n - 1], dp[1][n - 1]))

# -*- coding:utf-8 -*-

"""

created by shuangquan.huang at 1/16/20

"""

import collections
import time
import os
import sys
import bisect
import heapq
from typing import List

import math


def dist(posa, posb):
    return math.sqrt((posa[0] - posb[0]) ** 2 + (posa[1] - posb[1]) ** 2)


def solve(posa, posb, posc, bottles, N):
    if N == 1:
        print(min(dist(posa, bottles[0]), dist(posb, bottles[0])) + dist(posc, bottles[0]))
        return
    
    bottledist = [dist(posc, b) for b in bottles]
    da = [(dist(posa, bottles[i]) - bottledist[i], i) for i in range(N)]
    db = [(dist(posb, bottles[i]) - bottledist[i], i) for i in range(N)]
    da.sort()
    db.sort()
    d = 2 * sum(bottledist)
    ans = min(d + da[0][0], d + db[0][0])
    if da[0][1] != db[0][1]:
        ans = min(ans, d + da[0][0] + db[0][0])
    else:
        e = min(da[0][0] + db[1][0], da[1][0] + db[0][0])
        ans = min(ans, d + e)
    
    print(ans)
    
    
ax, ay, bx, by, cx, cy = list(map(int, input().split()))
N = int(input())
bottles = []
for i in range(N):
    x, y = list(map(int, input().split()))
    bottles.append((x, y))

solve((ax, ay), (bx, by), (cx, cy), bottles, N)


# -*- coding:utf-8 -*-

"""

created by shuangquan.huang at 1/16/20

"""

import collections
import time
import os
import sys
import bisect
import heapq
from typing import List

import math


def dist(posa, posb):
    return math.sqrt((posa[0] - posb[0]) ** 2 + (posa[1] - posb[1]) ** 2)


def solve(posa, posb, posc, bottles, N):
    if N == 1:
        print(min(dist(posa, bottles[0]), dist(posb, bottles[0])) + dist(posc, bottles[0]))
        return
    
    bottledist = [dist(posc, b) for b in bottles]
    da = [(dist(posa, bottles[i]) - bottledist[i], i) for i in range(N)]
    db = [(dist(posb, bottles[i]) - bottledist[i], i) for i in range(N)]
    d = 2 * sum(bottledist)
    
    heapq.heapify(da)
    heapq.heapify(db)
    a0 = heapq.heappop(da)
    b0 = heapq.heappop(db)
    ans = min(d + a0[0], d + b0[0])
    if a0[1] != b0[1]:
        ans = min(ans, d + a0[0] + b0[0])
    else:
        a1 = heapq.heappop(da)
        b1 = heapq.heappop(db)
        e = min(a0[0] + b1[0], a1[0] + b0[0])
        ans = min(ans, d + e)
    
    print(ans)
    
    
ax, ay, bx, by, cx, cy = list(map(int, input().split()))
N = int(input())
bottles = []
for i in range(N):
    x, y = list(map(int, input().split()))
    bottles.append((x, y))

solve((ax, ay), (bx, by), (cx, cy), bottles, N)


ax,ay,bx,by,tx,ty=list(map(int,input().split()))
n=int(input())
a,b=[],[]
res=0
for i in range(n):
    x, y=list(map(int, input().split()))
    lt=((tx-x)*(tx-x)+(ty-y)*(ty-y))**0.5
    la=((ax-x)*(ax-x)+(ay-y)*(ay-y))**0.5
    lb=((bx-x)*(bx-x)+(by-y)*(by-y))**0.5
    a+=[(la-lt,i)]
    b+=[(lb-lt,i)]
    res+=lt
a.sort();b.sort()
res*=2
if a[0][1]==b[0][1] and n>1:
    res+=min(a[0][0],b[0][0],a[0][0]+b[1][0],a[1][0]+b[0][0])
else: 
    if a[0][1]==b[0][1]:
        res+=min(a[0][0],b[0][0])
    else:
        res+=min(a[0][0],b[0][0],a[0][0]+b[0][0])
print(res)