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.

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Geometry

Dynamic programming

Implementation

Greedy algorithms


Solutions:
import math
import sys

def dist(u, v):
	return math.hypot(u[0] - v[0], u[1] - v[1])
(ax, ay, bx, by, tx, ty) = [int(x) for x in input().split()]
(a, b, t) = ((ax, ay), (bx, by), (tx, ty))
n = int(input())
bottles = [tuple((int(x) for x in line.split())) for line in sys.stdin]
S = sum((2 * dist(t, bottle) for bottle in bottles))
a_dist = [(dist(a, bottle) - dist(t, bottle), i) for (i, bottle) in enumerate(bottles)]
b_dist = [(dist(b, bottle) - dist(t, bottle), i) for (i, bottle) in enumerate(bottles)]
a_dist.sort()
b_dist.sort()
if a_dist[0][0] > 0 or b_dist[0][0] > 0 or n == 1:
	k = min(a_dist[0][0], b_dist[0][0])
elif a_dist[0][1] == b_dist[0][1]:
	k = min(a_dist[1][0] + b_dist[0][0], a_dist[0][0] + b_dist[1][0], a_dist[0][0], b_dist[0][0])
else:
	k = min(a_dist[0][0] + b_dist[0][0], a_dist[0][0], b_dist[0][0])
print(k + S)


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)


import math

def dst(p1, p2):
	(x1, y1) = p1
	(x2, y2) = p2
	result = math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
	return result

def min_dst(a, b, t, bs):
	bottles = [(dst(t, x), dst(a, x), dst(b, x)) for x in bs]
	full_dst = sum((2 * bot[0] for bot in bottles))
	min_a = full_dst - bottles[0][0] + bottles[0][1]
	min_b = full_dst - bottles[0][0] + bottles[0][2]
	min_ab = min(min_a, min_b)
	for i in range(1, len(bottles)):
		old_min_a = min_a
		old_min_b = min_b
		new_min_a = full_dst - bottles[i][0] + bottles[i][1]
		if new_min_a < min_a:
			min_a = new_min_a
		new_min_b = full_dst - bottles[i][0] + bottles[i][2]
		if new_min_b < min_b:
			min_b = new_min_b
		new_min_ab = min(old_min_b - bottles[i][0] + bottles[i][1], old_min_a - bottles[i][0] + bottles[i][2])
		if new_min_ab < min_ab:
			min_ab = new_min_ab
	return min(min_ab, min(min_a, min_b))
(ax, ay, bx, by, tx, ty) = map(int, input().split())
l = int(input())
bottles = [0] * l
for i in range(l):
	bottles[i] = tuple(map(int, input().split()))
print(min_dst((ax, ay), (bx, by), (tx, ty), bottles))


import math

def dist(x1, y1, x2, y2):
	res = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)
	res = math.sqrt(res)
	return res
(ax, ay, bx, by, tx, ty) = list(map(int, input().split()))
n = int(input())
ans = 0
bottles = [(0, 0) for i in range(n)]
da = [(0, -1) for i in range(n + 1)]
db = [(0, -1) for i in range(n + 1)]
for i in range(n):
	(xi, yi) = list(map(int, input().split()))
	bottles.append((xi, yi))
	dt = dist(xi, yi, tx, ty)
	ans += 2 * dt
	dist_a = dist(ax, ay, xi, yi) - dt
	da[i] = (dist_a, i)
	dist_b = dist(bx, by, xi, yi) - dt
	db[i] = (dist_b, i)
best = 10 ** 18
da = sorted(da)
db = sorted(db)
for i in range(min(3, n + 1)):
	for j in range(min(3, n + 1)):
		if da[i][1] == db[j][1]:
			continue
		if da[i][1] == -1 and db[j][1] == -1:
			continue
		best = min(best, da[i][0] + db[j][0])
print(ans + best)


import math

def dis(x1, y1, x2, y2):
	return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
str = input().split()
argu = []
for i in str:
	argu.append(int(i))
n = int(input())
total = 0
array = [[], []]
for i in range(n):
	(x, y) = input().split()
	x = int(x)
	y = int(y)
	td = dis(x, y, argu[4], argu[5])
	ad = dis(x, y, argu[0], argu[1])
	bd = dis(x, y, argu[2], argu[3])
	total += 2 * td
	array[0].append((i, ad - td))
	array[1].append((i, bd - td))
if n == 1:
	print('%.12f' % (total + min(array[0][0][1], array[1][0][1])))
else:

	def sortkey(x):
		return x[1]
	array[0].sort(key=sortkey)
	array[1].sort(key=sortkey)
	ans = total + array[0][0][1]
	ans = min(ans, total + array[1][0][1])
	for i in range(2):
		for j in range(2):
			tmpa = array[0][i]
			tmpb = array[1][j]
			if tmpa[0] != tmpb[0]:
				ans = min(ans, total + tmpa[1] + tmpb[1])
	print('%.12f' % ans)


read = lambda : map(int, input().split())
(ax, ay, bx, by, tx, ty) = read()
n = int(input())
p = [tuple(read()) for i in range(n)]
(a, b) = ([], [])
for i in range(n):
	(x, y) = p[i]
	pt = ((tx - x) ** 2 + (ty - y) ** 2) ** 0.5
	pa = ((ax - x) ** 2 + (ay - y) ** 2) ** 0.5
	pb = ((bx - x) ** 2 + (by - y) ** 2) ** 0.5
	a.append((pa - pt, i))
	b.append((pb - pt, i))
a.sort()
b.sort()
if a[0][1] == b[0][1] and n > 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 a[0][1] != b[0][1]:
		ans = min(ans, a[0][0] + b[0][0])
ans += sum((2 * ((tx - x) ** 2 + (ty - y) ** 2) ** 0.5 for (x, y) in p))
print(ans)


(ax, ay, bx, by, tx, ty) = map(int, input().split())
import math
n = int(input())
lisa = []
lisb = []
lis = []
inda = indb = -1
sa = sb = -100000000
cos = 0
for i in range(n):
	(a, b) = map(int, input().split())
	dis = math.sqrt((a - tx) ** 2 + (b - ty) ** 2)
	disa = math.sqrt((ax - a) ** 2 + (ay - b) ** 2)
	disb = math.sqrt((bx - a) ** 2 + (by - b) ** 2)
	lisa.append([dis - disa, i])
	lisb.append([dis - disb, i])
	lis.append(dis)
	cos += 2 * dis
lisa.sort(reverse=True)
lisb.sort(reverse=True)
if lisa[0][1] != lisb[0][1]:
	aa = max(lisa[0][0] + lisb[0][0], lisa[0][0], lisb[0][0])
	print(cos - aa)
else:
	aa = 0
	if len(lisa) > 1 and len(lisb) > 1:
		aa = max(lisa[0][0] + lisb[1][0], lisa[1][0] + lisb[0][0], lisa[0][0], lisb[0][0])
	elif len(lisa) > 1:
		aa = max(lisa[1][0] + lisb[0][0], lisa[0][0], lisb[0][0])
	elif len(lisb) > 1:
		aa = max(lisa[0][0] + lisb[1][0], lisa[0][0], lisb[0][0])
	elif len(lisa) == len(lisb) == 1:
		aa = max(lisa[0][0], lisb[0][0])
	print(cos - aa)


import math

def get_dist_vec(loc, loc_vec):
	dist_vec = []
	for loc2 in loc_vec:
		dist = (loc[0] - loc2[0]) ** 2 + (loc[1] - loc2[1]) ** 2
		dist_vec.append(dist ** 0.5)
	return dist_vec

def get_travel_saved(a_vec, r_vec):
	travel_saved_vec = []
	for i in range(len(a_vec)):
		travel_saved_vec.append(r_vec[i] - a_vec[i])
	idx_vec = sorted(range(len(travel_saved_vec)), key=lambda k: travel_saved_vec[k], reverse=True)
	return idx_vec

def get_dist_traveled(a_vec, b_vec, r_vec, i, j):
	if b_vec:
		dist_traveled = a_vec[i] + r_vec[i] + (b_vec[j] + r_vec[j])
	else:
		dist_traveled = a_vec[i] + r_vec[i]
	for k in range(len(r_vec)):
		if k == i or k == j:
			continue
		else:
			dist_traveled += 2 * r_vec[k]
	return dist_traveled

def main():
	args = [int(x) for x in input().split()]
	a_loc = (args[0], args[1])
	b_loc = (args[2], args[3])
	r_loc = (args[4], args[5])
	n = int(input())
	bottle_vec = []
	for i in range(n):
		bottle_coord = [int(x) for x in input().split()]
		bottle_vec.append((bottle_coord[0], bottle_coord[1]))
	a_vec = get_dist_vec(a_loc, bottle_vec)
	b_vec = get_dist_vec(b_loc, bottle_vec)
	r_vec = get_dist_vec(r_loc, bottle_vec)
	travel_saved_idx_vec_a = get_travel_saved(a_vec, r_vec)
	travel_saved_idx_vec_b = get_travel_saved(b_vec, r_vec)
	a_max_i = travel_saved_idx_vec_a[0]
	b_max_i = travel_saved_idx_vec_b[0]
	case1_traveled = math.inf
	if len(a_vec) > 1:
		if a_max_i == b_max_i:
			a_sec_max_i = travel_saved_idx_vec_a[1]
			b_sec_max_i = travel_saved_idx_vec_b[1]
			case1_saved = r_vec[a_max_i] - a_vec[a_max_i] + (r_vec[b_sec_max_i] - b_vec[b_sec_max_i])
			case2_saved = r_vec[b_max_i] - b_vec[b_max_i] + (r_vec[a_sec_max_i] - a_vec[a_sec_max_i])
			if case1_saved >= case2_saved:
				b_max_i = travel_saved_idx_vec_b[1]
			else:
				a_max_i = travel_saved_idx_vec_a[1]
		case1_traveled = get_dist_traveled(a_vec, b_vec, r_vec, a_max_i, b_max_i)
	a_max_i = travel_saved_idx_vec_a[0]
	case2_traveled = get_dist_traveled(a_vec, None, r_vec, a_max_i, a_max_i)
	b_max_i = travel_saved_idx_vec_b[0]
	case3_traveled = get_dist_traveled(b_vec, None, r_vec, b_max_i, b_max_i)
	print(min(case1_traveled, case2_traveled, case3_traveled))
main()


import sys
input = sys.stdin.readline

def dist(x1, y1, x2, y2):
	return (abs(x1 - x2) ** 2 + abs(y1 - y2) ** 2) ** 0.5
(ax, ay, bx, by, tx, ty) = map(int, input().split())
n = int(input())
xy = [list(map(int, input().split())) for i in range(n)]
s = 0
for i in range(n):
	(x, y) = xy[i]
	s += dist(tx, ty, x, y)
s *= 2
ans = 10 ** 18
ad = [[dist(ax, ay, xy[i][0], xy[i][1]) - dist(tx, ty, xy[i][0], xy[i][1]), i] for i in range(n)]
bd = [[dist(bx, by, xy[i][0], xy[i][1]) - dist(tx, ty, xy[i][0], xy[i][1]), i] for i in range(n)]
ad.sort()
bd.sort()
if ad[0][0] > 0 or bd[0][0] > 0 or n == 1:
	md = min(ad[0][0], bd[0][0])
	ans = min(ans, s + md)
elif ad[0][1] == bd[0][1]:
	md = min(ad[0][0] + bd[1][0], ad[1][0] + bd[0][0], ad[0][0], bd[0][0])
	ans = min(ans, s + md)
else:
	md = min(ad[0][0] + bd[0][0], ad[0][0], bd[0][0])
	ans = min(ans, s + md)
print(ans)


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):
	global 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)


import unittest
import sys

class Bottles:

	def __init__(self, test_inputs=None):
		it = iter(test_inputs.split('\n')) if test_inputs else None

		def uinput():
			return next(it) if it else sys.stdin.readline().rstrip()
		[self.ax, self.ay, self.bx, self.by, self.tx, self.ty] = map(int, uinput().split())
		self.n = int(uinput())
		(l, s) = (self.n, 2)
		inp = ' '.join((uinput() for i in range(l))).split()
		self.numm = [[int(inp[i]) for i in range(j, l * s, s)] for j in range(s)]
		(self.numa, self.numb) = self.numm

	def minn(self, l, skipi=set([])):
		result = None
		mini = None
		for i in range(len(l)):
			if i in skipi:
				continue
			if result is None or l[i] < result:
				mini = i
				result = l[i]
		return (result, mini)

	def hyp(self, a, b):
		return (a * a + b * b) ** 0.5

	def calculate(self):
		distt = [self.hyp(self.numa[i] - self.tx, self.numb[i] - self.ty) for i in range(self.n)]
		dista = [self.hyp(self.numa[i] - self.ax, self.numb[i] - self.ay) for i in range(self.n)]
		distb = [self.hyp(self.numa[i] - self.bx, self.numb[i] - self.by) for i in range(self.n)]
		distamt = [dista[i] - distt[i] for i in range(self.n)]
		distbmt = [distb[i] - distt[i] for i in range(self.n)]
		(min1, min1i) = self.minn(distamt)
		(min2, min2i) = self.minn(distbmt, skipi=set([min1i]))
		result1 = sum(distt) * 2 + min1 + (0 if min2 is None or min2 > 0 else min2)
		(min1, min1i) = self.minn(distbmt)
		(min2, min2i) = self.minn(distamt, skipi=set([min1i]))
		result2 = sum(distt) * 2 + min1 + (0 if min2 is None or min2 > 0 else min2)
		return str(min(result1, result2))

class unitTests(unittest.TestCase):

	def test_single_test(self):
		test = '3 1 1 2 0 0\n3\n1 1\n2 1\n2 3'
		d = Bottles(test)
		self.assertEqual(d.n, 3)
		self.assertEqual(d.numa, [1, 2, 2])
		self.assertEqual(d.numb, [1, 1, 3])
		self.assertEqual(Bottles(test).calculate(), '11.084259940083063')
		test = '5 0 4 2 2 0\n5\n5 2\n3 0\n5 5\n3 5\n3 3'
		self.assertEqual(Bottles(test).calculate(), '33.121375178')
		test = '0 0 1 1 2 2\n1\n1 3\n'

	def time_limit_test(self, nmax):
		import random
		import timeit
		test = str(nmax) + ' ' + str(nmax) + '\n'
		numnums = [str(i) + ' ' + str(i + 1) for i in range(nmax)]
		test += '\n'.join(numnums) + '\n'
		nums = [random.randint(1, 10000) for i in range(nmax)]
		test += ' '.join(map(str, nums)) + '\n'
		start = timeit.default_timer()
		d = Bottles(test)
		calc = timeit.default_timer()
		d.calculate()
		stop = timeit.default_timer()
		print('\nTimelimit Test: ' + '{0:.3f}s (init {1:.3f}s calc {2:.3f}s)'.format(stop - start, calc - start, stop - calc))
sys.setrecursionlimit(100000)
if sys.argv[-1] == '-ut':
	unittest.main(argv=[' '])
sys.stdout.write(Bottles().calculate())


from sys import stdin
import math

def diff(a, b, x, y):
	return math.sqrt((x - a) ** 2 + (y - b) ** 2)
(ax, ay, bx, by, tx, ty) = list(map(int, stdin.readline().split()))
ax -= tx
ay -= ty
bx -= tx
by -= ty
n = int(stdin.readline().strip())
points = []
dist = 0
for _ in range(n):
	(x, y) = list(map(int, stdin.readline().split()))
	x -= tx
	y -= ty
	points.append([x, y])
	dist += 2 * math.sqrt(x ** 2 + y ** 2)
min1a = float('inf')
mark1a = -1
for i in range(n):
	(x, y) = points[i]
	if dist - math.sqrt(x ** 2 + y ** 2) + diff(ax, ay, x, y) < min1a:
		min1a = dist - math.sqrt(x ** 2 + y ** 2) + diff(ax, ay, x, y)
		mark1a = i
mark1b = -1
min1b = min1a
for i in range(n):
	if mark1a != i:
		(x, y) = points[i]
		if min1a - math.sqrt(x ** 2 + y ** 2) + diff(bx, by, x, y) < min1b:
			min1b = min1a - math.sqrt(x ** 2 + y ** 2) + diff(bx, by, x, y)
			mark1b = i
min2b = float('inf')
mark2b = -1
for i in range(n):
	(x, y) = points[i]
	if dist - math.sqrt(x ** 2 + y ** 2) + diff(bx, by, x, y) < min2b:
		min2b = dist - math.sqrt(x ** 2 + y ** 2) + diff(bx, by, x, y)
		mark2b = i
mark2a = -1
min2a = min2b
for i in range(n):
	if mark2b != i:
		(x, y) = points[i]
		if min2b - math.sqrt(x ** 2 + y ** 2) + diff(ax, ay, x, y) < min2a:
			min2a = min2b - math.sqrt(x ** 2 + y ** 2) + diff(ax, ay, x, y)
			mark2a = i
if min1b < min2a:
	print(min1b)
else:
	print(min2a)


(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)


def readlist():
	return list(map(float, input().split()))

def dist(P1, P2):
	aa = P1[0] - P2[0]
	bb = P1[1] - P2[1]
	return (aa * aa + bb * bb) ** 0.5
(ax, ay, bx, by, tx, ty) = readlist()
A = [ax, ay]
B = [bx, by]
T = [tx, ty]
n = int(input())
Bottles = []
for i in range(n):
	Bottles.append(readlist())
dists_to_T = [dist(T, btl) for btl in Bottles]
sum_dists = 2 * sum(dists_to_T)
A_possible_wins = [dist(btl, T) - dist(A, btl) for btl in Bottles]
B_possible_wins = [dist(btl, T) - dist(B, btl) for btl in Bottles]
a_best = max(A_possible_wins)
b_best = max(B_possible_wins)
if a_best < 0 or b_best < 0 or len(Bottles) == 1:
	print(sum_dists - max(a_best, b_best))
else:
	a_pos = A_possible_wins.index(a_best)
	b_pos = B_possible_wins.index(b_best)
	if a_pos != b_pos:
		print(sum_dists - a_best - b_best)
	else:
		a_2best = max(A_possible_wins[:a_pos] + A_possible_wins[a_pos + 1:])
		b_2best = max(B_possible_wins[:b_pos] + B_possible_wins[b_pos + 1:])
		print(min(sum_dists - a_best - max(0, b_2best), sum_dists - max(0, a_2best) - b_best))


(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])
elif 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)


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size(10 ** 8)
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
sys.setrecursionlimit(300000)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=2 ** 51, func=lambda a, b: a & b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
(a, b, c, d, x, y) = map(int, input().split())
tot = 0
n = int(input())
r = []
r1 = []
ans = 0
for i in range(n):
	(qx, qy) = map(int, input().split())
	dis = math.sqrt((qx - a) ** 2 + (qy - b) ** 2)
	dis1 = math.sqrt((qx - c) ** 2 + (qy - d) ** 2)
	trash = math.sqrt((qx - x) ** 2 + (qy - y) ** 2)
	r.append(trash - dis)
	r1.append(trash - dis1)
	ans += trash * 2
s = SegmentTree(r)
s1 = SegmentTree(r1)
ma = -10 ** 10
for i in range(n):
	ma = max(ma, r[i] + max(0, s1.query(0, i - 1), s1.query(i + 1, n - 1)))
	ma = max(ma, r1[i] + max(0, s.query(0, i - 1), s.query(i + 1, n - 1)))
print(ans - ma)


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.0)
	m0 = m1 = m2 = m3 = -9000000000.0
	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.0 - max((m0, m2) if min(m0, m2) < 0.0 else ((m0 + m2) * (j != k), m0 + m3, m1 + m2, m0, m2)))

def __starting_point():
	main()
__starting_point()


__author__ = 'Utena'
import math
import operator
(ax, ay, bx, by, tx, ty) = map(int, input().split())
n = int(input())
D = []
DA = []
DB = []
for i in range(n):
	(x, y) = map(int, input().split())
	d = math.sqrt((x - tx) ** 2 + (y - ty) ** 2)
	da = math.sqrt((x - ax) ** 2 + (y - ay) ** 2)
	db = math.sqrt((x - bx) ** 2 + (y - by) ** 2)
	D.append(d)
	DA.append((d - da, i))
	DB.append((d - db, i))
DA = sorted(DA, key=operator.itemgetter(0), reverse=1)
DB = sorted(DB, key=operator.itemgetter(0), reverse=1)
if n == 1:
	if DA[0][0] and DB[0][0] < 0:
		m = max(DA[0][0], DB[0][0])
		ans = 2 * sum(D) - m
	elif DA[0][0] < 0 and DB[0][0] >= 0:
		ans = 2 * sum(D) - DB[0][0]
	elif DB[0][0] < 0 and DA[0][0] >= 0:
		ans = 2 * sum(D) - DA[0][0]
	elif DA[0][1] == DB[0][1]:
		m = max(DA[0][0], DB[0][0])
		ans = 2 * sum(D) - m
	else:
		m = DA[0][0] + DB[0][0]
		ans = 2 * sum(D) - m
elif DA[0][0] and DB[0][0] < 0:
	m = max(DA[0][0], DB[0][0])
	ans = 2 * sum(D) - m
elif DA[0][0] < 0 and DB[0][0] >= 0:
	ans = 2 * sum(D) - DB[0][0]
elif DB[0][0] < 0 and DA[0][0] >= 0:
	ans = 2 * sum(D) - DA[0][0]
elif DA[0][1] == DB[0][1]:
	m = max(DA[0][0] + DB[1][0], DA[1][0] + DB[0][0], DA[0][0] + 0, DB[0][0] + 0)
	ans = 2 * sum(D) - m
else:
	m = DA[0][0] + DB[0][0]
	ans = 2 * sum(D) - m
print(ans)


import os, io
from sys import stdout
import collections
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
import sys

def primes(n):
	sieve = [True] * n
	for i in range(3, int(n ** 0.5) + 1, 2):
		if sieve[i]:
			sieve[i * i::2 * i] = [False] * ((n - i * i - 1) // (2 * i) + 1)
	return [2] + [i for i in range(3, n, 2) if sieve[i]]

def binomial_coefficient(n, k):
	if 0 <= k <= n:
		ntok = 1
		ktok = 1
		for t in range(1, min(k, n - k) + 1):
			ntok *= n
			ktok *= t
			n -= 1
		return ntok // ktok
	else:
		return 0

def powerOfK(k, max):
	if k == 1:
		return [1]
	if k == -1:
		return [-1, 1]
	result = []
	n = 1
	while n <= max:
		result.append(n)
		n *= k
	return result

def divisors(n):
	i = 1
	result = []
	while i * i <= n:
		if n % i == 0:
			if n / i == i:
				result.append(i)
			else:
				result.append(i)
				result.append(n / i)
		i += 1
	return result

def digitsSum(n):
	if n == 0:
		return 0
	r = 0
	while n > 0:
		r += n % 10
		n //= 10
	return r

def isValid(i, j, n, m):
	return i >= 0 and i < n and (j >= 0) and (j < m)

def print_grid(grid):
	for line in grid:
		print(' '.join(map(str, line)))

def kadane(a, size):
	max_so_far = 0
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def prefixSum(arr):
	for i in range(1, len(arr)):
		arr[i] = arr[i] + arr[i - 1]
	return arr

def ceil(n, d):
	if n % d == 0:
		return n // d
	else:
		return n // d + 1

def distance(xa, ya, xb, yb):
	return ((ya - yb) ** 2 + (xa - xb) ** 2) ** 0.5
(xa, ya, xb, yb, xt, yt) = list(map(int, input().split()))
n = int(input())
import math
bottles = []
ans = 0
(ra, rb) = ([], [])
for _ in range(n):
	(xbt, ybt) = list(map(int, input().split()))
	bottles.append((xbt, ybt))
	da = distance(xa, ya, xbt, ybt)
	db = distance(xb, yb, xbt, ybt)
	dt = distance(xt, yt, xbt, ybt)
	ra.append((da - dt, xbt, ybt, dt))
	rb.append((db - dt, xbt, ybt, dt))
	ans += 2 * dt
ra = sorted(ra, key=lambda x: x[0])
rb = sorted(rb, key=lambda x: x[0])
if n == 1:
	print(ans + min(ra[0][0], rb[0][0]))
	exit()
a0 = ra[0]
a1 = ra[1]
b0 = rb[0]
b1 = rb[1]
if a0[0] <= 0 and b0[0] <= 0:
	if a0[1] == b0[1] and a0[2] == b0[2]:
		r = min(a0[0] + b1[0], b0[0] + a1[0])
		r = min(r, a0[0])
		r = min(r, b0[0])
		print(ans + r)
		exit()
	else:
		print(ans + a0[0] + b0[0])
		exit()
else:
	print(ans + min(a0[0], b0[0]))


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 = 1e+220
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
(ax, ay, bx, by, tx, ty) = map(float, input().split(' '))
n = int(input())
dis = 0.0
a1Dis = 100000000000.0 ** 2
a2Dis = 100000000000.0 ** 2
b1Dis = 100000000000.0 ** 2
b2Dis = 100000000000.0 ** 2
a1 = 0
b1 = 0
rec = 0.0
for i in range(n):
	(x, y) = map(float, input().split(' '))
	rec = math.sqrt((x - tx) ** 2 + (y - ty) ** 2)
	dis += rec * 2
	aDis = math.sqrt((x - ax) ** 2 + (y - ay) ** 2)
	if aDis - rec < a1Dis:
		a1 = i
		a2Dis = a1Dis
		a1Dis = aDis - rec
	elif aDis - rec < a2Dis:
		a2Dis = aDis - rec
	bDis = math.sqrt((x - bx) ** 2 + (y - by) ** 2)
	if bDis - rec < b1Dis:
		b1 = i
		b2Dis = b1Dis
		b1Dis = bDis - rec
	elif bDis - rec < b2Dis:
		b2Dis = bDis - rec
options = [a1Dis + b2Dis, b1Dis + a2Dis, a1Dis, b1Dis]
if a1 != b1:
	options.append(b1Dis + a1Dis)
print(dis + min(options))


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)


import sys
input = sys.stdin.readline
(ax, ay, bx, by, tx, ty) = map(int, input().strip().split())

def dd(x0, y0, x1, y1):
	return ((x0 - x1) ** 2 + (y0 - y1) ** 2) ** 0.5
n = int(input().strip())
arr = [list(map(int, input().strip().split())) for i in range(n)]
dist = [dd(x, y, tx, ty) for (x, y) in arr]
ans = sum(dist) * 2
a_dists = sorted(((dd(*x, ax, ay) - dd(*x, tx, ty), i) for (i, x) in enumerate(arr)))
b_dists = sorted(((dd(*x, bx, by) - dd(*x, tx, ty), i) for (i, x) in enumerate(arr)))
a_dists = a_dists[:2]
b_dists = b_dists[:2]
mi = 10 ** 100
for (dx, x) in a_dists:
	for (dy, y) in b_dists:
		if x != y:
			mi = min(mi, ans + dx + dy)
mi = min(mi, ans + min(a_dists[0][0], b_dists[0][0]))
print(mi)


import math

def dist(x1, y1, x2, y2):
	return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
(ax, ay, bx, by, tx, ty) = map(int, input().split())
n = int(input())
p = [tuple((int(x) for x in input().split())) for _ in range(n)]
da = [(dist(x[0], x[1], ax, ay) - dist(x[0], x[1], tx, ty), i) for (i, x) in enumerate(p)]
db = [(dist(x[0], x[1], bx, by) - dist(x[0], x[1], tx, ty), i) for (i, x) in enumerate(p)]
d = sum((2 * dist(x[0], x[1], tx, ty) for x in p))
da.sort()
db.sort()
(ca, cb) = (-1, -1)
md = 1e+20
if d + da[0][0] < md:
	md = d + da[0][0]
if d + db[0][0] < md:
	md = d + db[0][0]
if da[0][1] != db[0][1]:
	if d + da[0][0] + db[0][0] < md:
		md = d + da[0][0] + db[0][0]
elif n > 1:
	if d + da[1][0] + db[0][0] < md:
		md = d + da[1][0] + db[0][0]
	if d + da[0][0] + db[1][0] < md:
		md = d + da[0][0] + db[1][0]
print(md)


(ax, ay, bx, by, rx, ry) = map(int, input().split())
(a, b) = ([], [])
from math import sqrt
n = int(input())
for i in range(n):
	(m, rn) = map(int, input().split())
	a.append(m)
	b.append(rn)
(ra, rb) = ([], [])
ans = 0
for i in range(n):
	da = sqrt((ax - a[i]) ** 2 + (ay - b[i]) ** 2)
	db = sqrt((bx - a[i]) ** 2 + (by - b[i]) ** 2)
	dr = sqrt((rx - a[i]) ** 2 + (ry - b[i]) ** 2)
	ra.append(dr - da)
	rb.append(dr - db)
	ans += 2 * dr
l = range(n)
ran1 = sorted(zip(ra, l))[::-1]
ran2 = sorted(zip(rb, l))[::-1]
if n == 1:
	print(ans - max(ran1[0][0], ran2[0][0]))
elif ran1[0][0] >= 0 and ran2[0][0] >= 0:
	if ran1[0][1] != ran2[0][1]:
		print(ans - (ran1[0][0] + ran2[0][0]))
	else:
		print(ans - max(max(0, ran1[1][0]) + ran2[0][0], max(0, ran2[1][0]) + ran1[0][0]))
else:
	print(ans - max(ran1[0][0], ran2[0][0]))


(ax, ay, bx, by, tx, ty) = map(int, input().split())
n = int(input())
X = [0] * n
Y = [0] * n
T = [0.0] * n
res = 0.0
for i in range(n):
	(X[i], Y[i]) = map(int, input().split())
	T[i] = ((X[i] - tx) ** 2 + (Y[i] - ty) ** 2) ** 0.5
	res += T[i] * 2
L1 = [[0]] * (n + 2)
L2 = [[0]] * (n + 2)
for i in range(n + 2):
	L1[i] = [0.0] * 2
	L2[i] = [0.0] * 2
L1[n][1] = n
L2[n][1] = n
L1[n + 1][1] = -1
L2[n + 1][1] = -2
L1[n + 1][0] = ((tx - ax) ** 2 + (ty - ay) ** 2) ** 0.5
L2[n + 1][0] = ((tx - bx) ** 2 + (ty - by) ** 2) ** 0.5
for i in range(n):
	L1[i][0] = ((X[i] - ax) ** 2 + (Y[i] - ay) ** 2) ** 0.5 - T[i]
	L2[i][0] = ((X[i] - bx) ** 2 + (Y[i] - by) ** 2) ** 0.5 - T[i]
	L1[i][1] = L2[i][1] = i
L1.sort()
L2.sort()
d = 10 ** 18
for i in range(min(n + 2, 10)):
	for j in range(min(n + 2, 10)):
		if L1[i][1] != L2[j][1]:
			d = min(d, res + L1[i][0] + L2[j][0])
print(d)


def dis(x1, y1, x2, y2):
	return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
(ax, ay, bx, by, tx, ty) = map(int, input().split())
n = int(input())
(a, b, s) = ([], [], 0)
for i in range(n):
	(x, y) = map(int, input().split())
	dist = dis(tx, ty, x, y)
	a.append((dis(ax, ay, x, y) - dist, i))
	b.append((dis(bx, by, x, y) - dist, i))
	s += dist * 2
a.sort()
b.sort()
if n > 1 and a[0][1] == b[0][1]:
	res = min(a[0][0], b[0][0], a[0][0] + b[1][0], a[1][0] + b[0][0])
else:
	res = min(a[0][0], b[0][0])
	if n > 1:
		res = min(a[0][0] + b[0][0], res)
print(res + s)


(ax, ay, bx, by, tx, ty) = map(int, input().split())
n = int(input())
l = [tuple(map(int, input().split())) for _ in range(n)]
(a, b) = ([], [])
for i in range(n):
	(x, y) = l[i]
	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)]
a.sort()
b.sort()
if a[0][1] == b[0][1] and n > 1:
	ans = min(a[0][0], b[0][0], a[0][0] + b[1][0], a[1][0] + b[0][0])
elif a[0][1] == b[0][1]:
	ans = min(a[0][0], b[0][0])
else:
	ans = min(a[0][0], b[0][0], a[0][0] + b[0][0])
for i in range(n):
	(x, y) = l[i]
	lt = ((tx - x) * (tx - x) + (ty - y) * (ty - y)) ** 0.5
	ans += lt + lt
print(ans)


def D(x1, y1, x2, y2):
	return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
(Ax, Ay, Bx, By, Rx, Ry) = [float(_) for _ in input().split()]
N = int(input())
(PosX, PosY) = ([0.0] * N, [0.0] * N)
for i in range(N):
	(PosX[i], PosY[i]) = map(int, input().split())
(CutA, CutB) = ([0.0] * N, [0.0] * N)
ans = 0
for i in range(N):
	DA = D(PosX[i], PosY[i], Ax, Ay)
	DB = D(PosX[i], PosY[i], Bx, By)
	DR = D(PosX[i], PosY[i], Rx, Ry)
	CutA[i] = [i, DR - DA]
	CutB[i] = [i, DR - DB]
	ans += 2 * D(PosX[i], PosY[i], Rx, Ry)
CutA.sort(key=lambda x: x[1], reverse=True)
CutB.sort(key=lambda x: x[1], reverse=True)
CutCase = []
CutCase.append(CutA[0][1])
CutCase.append(CutB[0][1])
if N >= 2:
	if CutA[0][0] != CutB[0][0]:
		CutCase.append(CutA[0][1] + CutB[0][1])
	else:
		CutCase.append(CutA[0][1] + CutB[1][1])
		CutCase.append(CutA[1][1] + CutB[0][1])
ans -= max(CutCase)
print(ans)


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)


import sys
import math

def top2(sx, sy, tx, ty, n, px, py):
	t1 = -1e+18
	p1 = -1
	t2 = -1e+18
	p2 = -1
	for i in range(n):
		v = math.sqrt((px[i] - tx) ** 2 + (py[i] - ty) ** 2) - math.sqrt((px[i] - sx) ** 2 + (py[i] - sy) ** 2)
		if v > t1:
			t2 = t1
			p2 = p1
			t1 = v
			p1 = i
		elif v > t2:
			t2 = v
			p2 = i
	return [t1, p1, t2, p2]
(ax, ay, bx, by, tx, ty) = [int(i) for i in sys.stdin.readline().strip().split()]
n = int(sys.stdin.readline())
px = [0] * n
py = [0] * n
for i in range(n):
	(px[i], py[i]) = [int(i) for i in sys.stdin.readline().strip().split()]
sum = 0
for i in range(n):
	sum += 2 * math.sqrt((px[i] - tx) ** 2 + (py[i] - ty) ** 2)
(at1, ap1, at2, ap2) = top2(ax, ay, tx, ty, n, px, py)
(bt1, bp1, bt2, bp2) = top2(bx, by, tx, ty, n, px, py)
res = sum - max(at1, bt1)
if ap1 == bp1:
	if ap2 != -1:
		res = min(res, sum - at1 - bt2)
		res = min(res, sum - bt1 - at2)
else:
	res = min(res, sum - at1 - bt1)
print(res)


from math import pow, sqrt
(ax, ay, bx, by, tx, ty) = map(int, input().split())
n = int(input())
x = [None] * n
y = [None] * n
for i in range(n):
	(x[i], y[i]) = map(int, input().split())

def dist(x1, y1, x2, y2):
	return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2))
full = 2 * sum((dist(tx, ty, x[i], y[i]) for i in range(n)))

def best_two(sx, sy):
	(b1, b2) = (float('inf'), float('inf'))
	(b1i, b2i) = (None, None)
	for i in range(n):
		d = dist(sx, sy, x[i], y[i]) - dist(tx, ty, x[i], y[i])
		if d < b1:
			(b2, b2i) = (b1, b1i)
			(b1, b1i) = (d, i)
		elif d < b2:
			(b2, b2i) = (d, i)
	return (b1, b2, b1i, b2i)
(ab1, ab2, ab1i, ab2i) = best_two(ax, ay)
(bb1, bb2, bb1i, bb2i) = best_two(bx, by)
if n == 1:
	print(full + min(ab1, bb1))
elif ab1i != bb1i:
	print(full + min(ab1 + bb1, ab1, bb1))
else:
	print(full + min(ab1 + bb2, ab2 + bb1, ab1, bb1))


import math

def read_ints():
	return [int(x) for x in input().split()]

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

def main():
	(ax, ay, bx, by, tx, ty) = read_ints()
	(n,) = read_ints()
	a = []
	b = []
	total = 0
	for i in range(0, n):
		(x, y) = read_ints()
		distance_to_bin = dist(tx, ty, x, y)
		total += 2 * distance_to_bin
		cost1 = distance_to_bin - dist(ax, ay, x, y)
		cost2 = distance_to_bin - dist(bx, by, x, y)
		a.append((cost1, i))
		b.append((cost2, i))
	a.sort(key=lambda s: s[0], reverse=True)
	b.sort(key=lambda s: s[0], reverse=True)
	res = []
	if a[0][1] != b[0][1]:
		res.append(total - a[0][0] - b[0][0])
	if n > 1 and a[0][1] != b[1][1]:
		res.append(total - a[0][0] - b[1][0])
	if n > 1 and a[1][0] != b[0][1]:
		res.append(total - a[1][0] - b[0][0])
	res.append(total - a[0][0])
	res.append(total - b[0][0])
	print(min(res))
main()


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)


from math import hypot

def dist(a, b):
	return hypot(a[0] - b[0], a[1] - b[1])
(ax, ay, bx, by, tx, ty) = map(float, input().split())
n = int(input())
p = []
ans = 0
for _ in range(n):
	(x, y) = map(float, input().split())
	p.append((x, y))
	ans += 2 * dist((x, y), (tx, ty))
(v1, v2) = ([(0, -1)], [(0, -1)])
for i in range(n):
	v1.append((dist(p[i], (ax, ay)) - dist(p[i], (tx, ty)), i))
	v2.append((dist(p[i], (bx, by)) - dist(p[i], (tx, ty)), i))
v1.sort()
v2.sort()
mnadd = 1000000000000000.0
for i in range(0, min(len(v1), 5)):
	for j in range(0, min(len(v2), 5)):
		if v1[i][1] != v2[j][1]:
			mnadd = min(mnadd, v1[i][0] + v2[j][0])
print(ans + mnadd)


import sys

def calc_dist(x, y, x2, y2):
	return ((x - x2) ** 2 + (y - y2) ** 2) ** 0.5
inp = sys.stdin.read().splitlines()
line0 = inp[0].split()
(Ax, Ay, Bx, By, Tx, Ty) = (int(line0[0]), int(line0[1]), int(line0[2]), int(line0[3]), int(line0[4]), int(line0[5]))
totaldist = 0
Alst = []
Blst = []
for i in range(2, int(inp[1]) + 2):
	cood = inp[i].split()
	x = int(cood[0])
	y = int(cood[1])
	Tdist = calc_dist(x, y, Tx, Ty)
	totaldist += Tdist
	Adist = calc_dist(x, y, Ax, Ay)
	Bdist = calc_dist(x, y, Bx, By)
	Asave = Tdist - Adist
	Bsave = Tdist - Bdist
	Alst.append(Asave)
	Blst.append(Bsave)
Amax = max(Alst)
Bmax = max(Blst)
maxsave = max([Amax + Bmax, Amax, Bmax])
if maxsave == Amax + Bmax:
	Aindex = Alst.index(Amax)
	Bindex = Blst.index(Bmax)
	if Aindex == Bindex:
		Alst[Aindex] = -1000000000.0
		Amax2 = max(Alst)
		Blst[Bindex] = -1000000000.0
		Bmax2 = max(Blst)
		maxsave = max(Amax2 + Bmax, Amax + Bmax2, Amax, Bmax)
final = totaldist * 2 - maxsave
print(final)


import math

def dist(a, b):
	x = abs(a[0] - b[0])
	y = abs(a[1] - b[1])
	return math.sqrt(x * x + y * y)

def path(a, b, c):
	return dist(a, b) + dist(b, c)

def findb(ap, bp, tp, gb):
	adiff = -10000000000.0
	abest = set()
	for gp in gb:
		x = dist(gp, tp) - dist(ap, gp)
		if x > adiff:
			adiff = x
			abest = gp
	bdiff = 0.0
	for gp in gb:
		if gp == abest:
			continue
		x = dist(gp, tp) - dist(bp, gp)
		if x > bdiff:
			bdiff = x
	return adiff + bdiff

def solve():
	(ax, ay, bx, by, tx, ty) = [int(x) for x in input().split()]
	n = int(input())
	gb = []
	for _ in range(n):
		(a, b) = [int(x) for x in input().split()]
		gb.append((a, b))
	ap = (ax, ay)
	bp = (bx, by)
	tp = (tx, ty)
	total = 0.0
	for gp in gb:
		total += dist(gp, tp) * 2
	aa = findb(ap, bp, tp, gb)
	bb = findb(bp, ap, tp, gb)
	if aa > bb:
		print(total - aa)
	else:
		print(total - bb)
solve()


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]))


from math import hypot
(ax, ay, bx, by, tx, ty) = [int(x) for x in input().split()]
n = int(input())
(a, b, r) = ([], [], [])
for _ in range(n):
	(x, y) = [int(x) for x in input().split()]
	a.append(hypot(ax - x, ay - y))
	b.append(hypot(bx - x, by - y))
	r.append(hypot(tx - x, ty - y))
ans = 2 * sum(r)
t1 = [x - y for (x, y) in zip(a, r)]
t2 = [x - y for (x, y) in zip(b, r)]
amin = min(t1)
bmin = min(t2)
if n == 1:
	ans += min(amin, bmin)
	print(ans)
	exit()
if amin < 0 and bmin < 0:
	i = t1.index(amin)
	j = t2.index(bmin)
	if i == j:
		t1[i] = 2000000000.0
		t2[j] = 2000000000.0
		a2min = min(t1)
		b2min = min(t2)
		a2min = min(0, a2min)
		b2min = min(0, b2min)
		ans += min(amin + b2min, bmin + a2min)
	else:
		ans += amin + bmin
else:
	ans += min(amin, bmin)
print(ans)


line = list(map(int, input().split(' ')))
(A, B, T) = zip(line[::2], line[1::2])
n = int(input())
bottles = [tuple(map(int, input().split(' '))) for _ in range(n)]

def dist(x, y):
	return abs(complex(*x) - complex(*y))

def keyFun(x, a):
	return dist(T, bottles[x]) - dist(a, bottles[x])
if n == 1:
	ret = min(dist(bottles[0], A) + dist(bottles[0], T), dist(bottles[0], B) + dist(bottles[0], T))
	print(format(ret, '.100f'))
	exit()
ret = float('inf')
allSum = sum(map(lambda x: dist(x, T) * 2, bottles))
for (a, b) in ((A, B), (B, A)):
	best1 = max(range(n), key=lambda x: keyFun(x, a))
	best2 = max((i for i in range(n) if i != best1), key=lambda x: keyFun(x, b))
	ret = min(ret, allSum + dist(a, bottles[best1]) - dist(T, bottles[best1]) + min(0, dist(b, bottles[best2]) - dist(T, bottles[best2])))
print(format(ret, '.100f'))


from math import sqrt
(ax, ay, bx, by, tx, ty) = 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) = 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)


def glen(x1, y1, x2, y2):
	return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
(xa, ya, xb, yb, xt, yt) = map(int, input().split())
n = int(input())
x = [0] * n
y = [0] * n
for i in range(n):
	(x[i], y[i]) = map(int, input().split())
inf = 10 ** 10
afmin = [0, 0]
asmin = [0, 0]
for i in range(n):
	a = glen(xa, ya, x[i], y[i]) - glen(xa, ya, xt, yt) - glen(xt, yt, x[i], y[i])
	if asmin[0] > a:
		asmin[0] = a
		asmin[1] = i
	if asmin[0] < afmin[0]:
		(asmin, afmin) = (afmin, asmin)
bfmin = [0, 0]
bsmin = [0, 0]
for i in range(n):
	b = glen(xb, yb, x[i], y[i]) - glen(xb, yb, xt, yt) - glen(xt, yt, x[i], y[i])
	if bsmin[0] > b:
		bsmin[0] = b
		bsmin[1] = i
	if bsmin[0] < bfmin[0]:
		(bsmin, bfmin) = (bfmin, bsmin)
res = 0
b = bfmin[1]
a = afmin[1]
b1 = bsmin[1]
a1 = asmin[1]
res1 = min(glen(x[a], y[a], xa, ya) - glen(x[a], y[a], xt, yt), glen(x[b], y[b], xb, yb) - glen(x[b], y[b], xt, yt))
if b != a:
	res += glen(x[a], y[a], xa, ya) - glen(x[a], y[a], xt, yt)
	res += glen(x[b], y[b], xb, yb) - glen(x[b], y[b], xt, yt)
else:
	res += min(glen(x[a], y[a], xa, ya) - glen(x[a], y[a], xt, yt) + glen(x[b1], y[b1], xb, yb) - glen(x[b1], y[b1], xt, yt), glen(x[a1], y[a1], xa, ya) - glen(x[a], y[a], xt, yt) + glen(x[b], y[b], xb, yb) - glen(x[b1], y[b1], xt, yt))
for i in range(n):
	res += 2 * glen(xt, yt, x[i], y[i])
	res1 += 2 * glen(xt, yt, x[i], y[i])
if n == 1:
	res = 10 ** 11
print(min(res, res1))


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

def second_smallest(arr, temp_x, temp_y, tx, ty):
	smallest_index = arr.index(max(arr, key=lambda T: distance(tx, ty, *T) - distance(ax, ay, *T)))
	d = 10 ** 20
	index = -1
	for (i, v) in enumerate(arr):
		(x, y) = v
		dist = -distance(x, y, tx, ty) + distance(x, y, temp_x, temp_y)
		if dist < d and smallest_index != i:
			d = dist
			index = i
	return index
(ax, ay, bx, by, tx, ty) = map(int, input().split())
n = int(input())
arr = list()
for i in range(n):
	(x, y) = map(int, input().split())
	arr.append((x, y))
if n == 1:
	print(min(distance(ax, ay, *arr[0]), distance(bx, by, *arr[0])) + distance(tx, ty, *arr[0]))
	exit()
distances = [(distance(ax, ay, x, y), distance(bx, by, x, y), distance(tx, ty, x, y)) for (x, y) in arr]
ans = 2 * sum((v[2] for v in distances))
index1 = distances.index(max(distances, key=lambda T: T[2] - T[0]))
index2 = distances.index(max(distances, key=lambda T: T[2] - T[1]))
if index1 != index2:
	if distance(tx, ty, *arr[index1]) > distance(ax, ay, *arr[index1]):
		ans -= distance(tx, ty, *arr[index1])
		ans += distance(ax, ay, *arr[index1])
	if distance(tx, ty, *arr[index2]) > distance(bx, by, *arr[index2]):
		ans -= distance(tx, ty, *arr[index2])
		ans += distance(bx, by, *arr[index2])
	if distance(tx, ty, *arr[index1]) < distance(ax, ay, *arr[index1]) and distance(tx, ty, *arr[index2]) < distance(bx, by, *arr[index2]):
		(p, q) = (distance(tx, ty, *arr[index1]) - distance(ax, ay, *arr[index1]), distance(tx, ty, *arr[index2]) - distance(bx, by, *arr[index2]))
		ans -= max(p, q)
	print(ans)
else:
	(p, q) = (ans, ans)
	p -= distance(tx, ty, *arr[index1])
	p += distance(ax, ay, *arr[index1])
	temp_index = second_smallest(arr, bx, by, tx, ty)
	if distance(bx, by, *arr[temp_index]) < distance(tx, ty, *arr[temp_index]):
		p -= distance(tx, ty, *arr[temp_index])
		p += distance(bx, by, *arr[temp_index])
	q -= distance(tx, ty, *arr[index2])
	q += distance(bx, by, *arr[index2])
	temp_index = second_smallest(arr, ax, ay, tx, ty)
	if distance(ax, ay, *arr[temp_index]) < distance(tx, ty, *arr[temp_index]):
		q -= distance(tx, ty, *arr[temp_index])
		q += distance(ax, ay, *arr[temp_index])
	print(min(p, q))


import math
(ax, ay, bx, by, tx, ty) = list(map(int, input().split()))
n = int(input())
p = [0, 0] * n
s = [0.0] * n
ma = [0.0] * n
mb = [0.0] * n
for i in range(n):
	p[i] = list(map(int, input().split()))
	s[i] = math.hypot(tx - p[i][0], ty - p[i][1])
	ma[i] = math.hypot(ax - p[i][0], ay - p[i][1]) - s[i]
	mb[i] = math.hypot(bx - p[i][0], by - p[i][1]) - s[i]
ma = sorted(dict(zip(range(n), ma)).items(), key=lambda t: t[1])
mb = sorted(dict(zip(range(n), mb)).items(), key=lambda t: t[1])
if ma[0][1] > 0 and mb[0][1] > 0:
	ans = min(ma[0][1], mb[0][1])
elif ma[0][0] == mb[0][0]:
	if n == 1:
		ans = min(ma[0][1], mb[0][1], 0)
	else:
		(a1, a2, b1, b2) = (min(ma[0][1], 0), min(ma[1][1], 0), min(mb[0][1], 0), min(mb[1][1], 0))
		ans = min(a1 + b2, a2 + b1, 0)
else:
	ans = min(ma[0][1], 0) + min(mb[0][1], 0)
print(2 * sum(s) + ans)