Problem: 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 yu > yv.

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.

Input

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: xi, yi (|xi|, |yi| ≤ 103) — coordinates of the nodes. It is guaranteed that all points are distinct.

Output

If it is impossible to build a binary root tree on the given points, print "-1". Otherwise, print a single real number — the total length of the arcs in the minimum binary tree. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6. 

Examples

Input

3
0 0
1 0
2 1


Output

3.650281539872885


Input

4
0 0
1 0
2 1
2 0


Output

-1

Solution (in JAVA):

Solution:
import java.io.*;
import java.util.*;
public class Binary{
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.flush();out.close();
    }
        static class TaskE {
            class pair{
                int F , S;
                pair(int a, int b){F = a; S = b;}
            }
            final int gmax = Integer.MAX_VALUE;
            final int max = 123456;
            ArrayList<pair> al = new ArrayList<>();
            int n;
            double dist[][];
            double dist(int x , int y){
                pair a = al.get(x - 1) , b = al.get(y - 1);
                return Math.sqrt((a.F - b.F) * (a.F - b.F) + (a.S - b.S) * (a.S - b.S));
            }
            class MinCostMaxFlow{
                ArrayList<Edge> al[];
                Edge ja[][]; 
                int rcap[][]; // residual capacity
                double d[]; // shortest distances
                int N , S , T , maxFlow ; double minCost;
                
                int edges = 0;

                class Edge{
                    int u , flow; double cost;
                    Edge(int a, int b, double c){u = a; flow = b; cost = c;}
                }
                
                void addEdge(int u , int v , int flow , double cost){
                    al[u].add(new Edge(v, flow, cost)); rcap[u][v] = flow;
                    al[v].add(new Edge(u, 0, -cost));   rcap[v][u] = 0;
                }
                
                void convertToArray(){
                    ja = new Edge[N][];
                    for(int i = 0; i < N; i++){
                        int sz = al[i].size();
                        ja[i] = new Edge[sz];
                        for(int j = 0; j < sz; j++){
                            ja[i][j] = al[i].get(j);
                        }
                        al[i].clear();
                    }
                }
                
                MinCostMaxFlow(int n , int source , int sink){
                    N = n; S = source; T = sink; maxFlow = 0; minCost = 0;
                    rcap = new int[N][N];
                    al = new ArrayList[N];
                    d = new double[N];
                    for(int i = 0; i < N; i++){
                        al[i] = new ArrayList<>();
                    }
                }
                
                boolean BellmanFord(boolean check){
                    d[0] = 0;
                    for(int i = 0; i < N - 1; i++){
                        for(int j = 0; j < N; j++){
                            for(Edge e : ja[j]){
                                if(rcap[j][e.u] == 0)continue; // not to consider reverse edges
                                d[e.u] = Math.min(d[e.u] , d[j] + e.cost);
                            }
                        }
                    }
                    if(check){// check for negative cycles
                        for(int j = 0; j < N; j++){
                            for(Edge e : ja[j]){
                                if(rcap[j][e.u] == 0)continue;
                                if(d[j] + e.cost < d[e.u]) return false;
                            }
                        }   
                    }return true;
                }

                int node[]; // present node 

                int visit[]; // 0 -> not added 1 -> not removed 2 -> removed
                int prv[]; // previous node for augmentation
                double dist[]; // min dist

                boolean simple(){
                    node = new int[N]; 
                    visit = new int[N]; 
                    prv = new int[N];
                    dist = new double[N];   Arrays.fill(dist , gmax);

                    node[0] = S; dist[0] = 0;
                    int front = 1, back = 0;
                    while(front != back){
                        int u = node[back++]; double distu = dist[u];
                        if(back == N)back = 0;
                        visit[u] = 2;
                        for(Edge e : ja[u]){
                            if(rcap[u][e.u] == 0)continue;
                            double cdist = distu + e.cost; // no need of reduced cost
                            if(cdist < dist[e.u]){
                                if(visit[e.u] == 0){
                                    node[front] = e.u; 
                                    if(++front == N)front = 0;
                                }else if(visit[e.u] == 2){
                                    if(--back == -1)back += N;
                                    node[back] = e.u;
                                }
                                visit[e.u] = 1;
                                prv[e.u] = u; dist[e.u] = cdist;
                            }
                        }
                    }
                    return visit[T] != 0;
                }

                class pair{
                    int F; double S;
                    pair(int a, double b){F = a; S = b;}
                }

                // no need to update the reduced costs if initial costs are negative
                boolean dijkstra(){
                    visit = new int[N];
                    prv = new int[N];
                    dist = new double[N]; Arrays.fill(dist, gmax);
                    PriorityQueue<pair> pq = new PriorityQueue<>((A, B) -> Double.compare(A.S , B.S));

                    pq.add(new pair(S , 0)); dist[0] = 0;
                    o : while(!pq.isEmpty()){
                        pair p = pq.poll();
                        while(dist[p.F] < p.S){
                            if(pq.isEmpty()) break o; // had a better val 
                            p = pq.poll();
                        }
                        visit[p.F] = 2;
                        for(Edge e : ja[p.F]){
                            if(rcap[p.F][e.u] == 0)continue; // important
                            double cdist = p.S + (e.cost + d[p.F] - d[e.u]); // reduced cost
                            if(cdist < dist[e.u]){ 
                                if(visit[e.u] == 2) return false;
                                pq.add(new pair(e.u , cdist));
                                dist[e.u] = cdist; prv[e.u] = p.F;
                                visit[e.u] = 1;
                            }
                        }
                    }
                    return visit[T] != 0;
                }
                
                int augment(){
                    int p = T; int min = gmax;
                    while(p != 0){
                        int pp = prv[p];
                        int val = rcap[pp][p];
                        min = Math.min(min , val);
                        p = pp;
                    }
                    p = T;
                    while(p != 0){
                        int pp = prv[p];
                        rcap[pp][p] -= min;
                        rcap[p][pp] += min;
                        p = pp;
                    }
                    maxFlow += min;
                    return min;
                }

                // if(dist[T] >= 0)return true; // non contributing flow
                boolean calSimple(){
                    // uncomment to check for negative cycles
                    /* boolean possible = BellmanFord(true); 
                     if(!possible) return false; */
                    while(simple()){
                        /*if(dist[T] >= 0)return true;*/ 
                        minCost += dist[T] * augment();
                    }
                    return true;
                }

                void updPotential(){
                    for(int i = 0; i < N; i++){
                        if(visit[i] != 0){
                            d[i] += dist[i] - dist[S];
                        }
                    }
                }
                boolean calWithPotential(){
                    // set true to check for negative cycles
                    boolean possible = BellmanFord(false); 
                    if(!possible) return false;
                    while(dijkstra()){
                        double min = dist[T] + d[T] - d[S]; // getting back the original cost
                        /*if(dist[T] >= 0)return true;*/
                        minCost += min * augment();
                        updPotential();
                    }
                    return true;   
                }
            }

           public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt();
            for(int i = 0; i < n; i++){
                al.add(new pair(in.nextInt(), in.nextInt()));
            }
            Collections.sort(al , (A, B) -> A.S == B.S ? A.F - B.F : B.S - A.S);
            dist = new double[n + 1][n + 1];
            for(int i = 1; i < n; i++){
                for(int j = i + 1; j <= n; j++){
                    dist[i][j] = dist(i , j);
                }
            }
            // S + 2 * n + T 
            MinCostMaxFlow ans = new MinCostMaxFlow(2 * n + 2, 0, 2 * n + 1);

            for(int i = n + 1; i <= 2 * n; i++){
                ans.addEdge(0 , i , 2 , 0);
            }
            for(int i = 1; i < n; i++){
                pair p1 = al.get(i - 1);
                for(int j = i + 1; j <= n; j++){
                    pair p2 = al.get(j - 1);
                    if(p2.S != p1.S){
                        ans.addEdge(n + i , j , 1 , dist[i][j]);
                    }
                }
            }
            for(int i = 1; i <= n; i++){
                ans.addEdge(i , 2 * n + 1 , 1 , 0);
            }
            ans.convertToArray();
            ans.calWithPotential();
            // ans.calSimple();
            // System.out.println(ans.maxFlow);
            if(ans.maxFlow != n - 1){
                out.println(-1); return;
            }
            out.println(ans.minCost);
          }
    }
    static class InputReader {
        BufferedReader br;
        StringTokenizer st;
        public InputReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
            st = null;
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}