A root tree is a directed acyclic graph that contains one node (root), from which there is exactly one path to any other node.

A root tree is binary if each node has at most two outgoing arcs.

When a binary tree is painted on the plane, all arcs should be directed from top to bottom. That is, each arc going from *u* to *v* must meet the condition *y*<sub class="lower-index">*u*</sub> &gt; *y*<sub class="lower-index">*v*</sub>.

You've been given the coordinates of all tree nodes. Your task is to connect these nodes by arcs so as to get the binary root tree and make the total length of the arcs minimum. All arcs of the built tree must be directed from top to bottom.
The first line contains a single integer *n* (2 ≤ *n* ≤ 400) — the number of nodes in the tree. Then follow *n* lines, two integers per line: *x*<sub class="lower-index">*i*</sub>, *y*<sub class="lower-index">*i*</sub> (|*x*<sub class="lower-index">*i*</sub>|, |*y*<sub class="lower-index">*i*</sub>| ≤ 10<sup class="upper-index">3</sup>) — coordinates of the nodes. It is guaranteed that all points are distinct.
import queue
import math

class Edge():
    def __init__(self):
        self.to = 0
        self.next = 0
        self.cap = 0
        self.flow = 0
        self.cost = 0.0

class mcmf():
    def __init__(self, maxn, maxm):
        self.maxn = maxn
        self.maxm = maxm
        self.edge = []
        for i in range(maxm):
            self.edge.append(Edge())
        self.head = [0]*maxn
        self.pre = [0]*maxn
        self.dis = [0.0]*maxn
        self.vis = [False]*maxn
        self.init()
    
    def init(self):
        self.tol = 0
        for i in range(self.maxn):
            self.head[i] = -1
    
    def addedge(self, u, v, cap, cost):
        self.edge[self.tol].to = v
        self.edge[self.tol].cap = cap
        self.edge[self.tol].cost = cost
        self.edge[self.tol].flow = 0
        self.edge[self.tol].next = self.head[u]
        self.head[u] = self.tol;
        self.tol += 1
        self.edge[self.tol].to = u
        self.edge[self.tol].cap = 0
        self.edge[self.tol].cost = -cost
        self.edge[self.tol].flow = 0
        self.edge[self.tol].next = self.head[v]
        self.head[v] = self.tol;
        self.tol += 1

    def spfa(self, s, t):
        q = queue.Queue()
        for i in range(self.maxn):
            self.dis[i] = 1e20
            self.vis[i] = False
            self.pre[i] = -1
        self.dis[s] = 0
        self.vis[s] = True
        q.put(s)

        while not q.empty():
            u = q.get()
            self.vis[u] = False
            i = self.head[u]
            while i!=-1:
                v = self.edge[i].to
                if self.edge[i].cap > self.edge[i].flow and self.dis[v] > self.dis[u] + self.edge[i].cost:
                    self.dis[v] = self.dis[u] + self.edge[i].cost
                    self.pre[v] = i
                    if not self.vis[v]:
                        self.vis[v] = True
                        q.put(v)
                i = self.edge[i].next
        
        if self.pre[t]==-1:
            return False
        return True

    def solve(self, s, t):
        flow = 0
        cost = 0.0
        while self.spfa(s,t):
            Min = 1e20

            i = self.pre[t]
            while i!=-1:
                if Min>self.edge[i].cap-self.edge[i].flow:
                    Min = self.edge[i].cap-self.edge[i].flow
                i = self.pre[self.edge[i^1].to]

            i = self.pre[t]
            while i!=-1:
                self.edge[i].flow += Min
                self.edge[i^1].flow -= Min
                cost += self.edge[i].cost*Min
                i = self.pre[self.edge[i^1].to]

            flow += Min
        
        return flow, cost

# test in codeforces 277E
p = []
def dist(i,j):
    x = (p[i][0]-p[j][0])**2
    y = (p[i][1]-p[j][1])**2
    return math.sqrt(x+y)
net = mcmf(805,320005)
n = int(input())
net.init()
for i in range(n):
    uv = input().strip().split()
    uv = [int(k.strip()) for k in uv]
    p.append(uv)
def mykey(x):
    return -x[1]*10000000+x[0]
p.sort(key=mykey)
for i in range(1,n+1):
    net.addedge(0,i,1,0)
for i in range(n+1,n+n+1):
    net.addedge(i,n+n+1,2,0)
for i in range(1,n+1):
    for j in range(i+1,n+1):
        if p[i-1][1] > p[j-1][1]:
            net.addedge(j,i+n,1,dist(i-1,j-1))
flow,cost = net.solve(0,2*n+1)
if flow==n-1:
    print(cost)
else:
    print('-1')