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.util.ArrayList;
    import java.util.Arrays;
    import java.util.Scanner;
    
    
    public class Main {
    
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            int vertices = in.nextInt();
            GraphFactory factory = new GraphFactory(vertices);
            for (int i=0; i<vertices; i++) {
                Point point = new Point(in.nextInt(), in.nextInt());
                factory.addPoint(point); 
            }
            in.close();
            Graph graph = factory.getGraph();
            double[] flow = graph.getMaxFlow();
            if (flow[0] < vertices-1)
                System.out.println("-1");
            else 
                System.out.println(flow[1]);
        }
    
    }
    
    class Point {
        int x,y;
            
        public Point(int x, int y) {
            this.x = x;
            this.y = y;
        }
        
        public double getDistance(Point o) {
            return Math.sqrt((this.x - o.x) * (this.x - o.x) + (this.y - o.y) * (this.y - o.y));
        }
        
        public boolean isLower(Point o) {
            return this.y < o.y;
        }
    }
    
    class GraphFactory {
        
        int vertices;
        ArrayList<Point> points;
        
        public GraphFactory(int vertices) {
            this.vertices = vertices;
            this.points = new ArrayList<Point>();
        }
        
        public void addPoint(Point point) {
            points.add(point);
        }
        
        private int getFirstIndex(int i) {
            return i+1;
        }
        
        private int getSecondIndex(int i) {
            return vertices+1+i;
        }
        
        
        public Graph getGraph() {
            Graph graph = new Graph(2*vertices+2);
            for (int i =0; i< points.size(); i++) {
                graph.addEdge(0, getFirstIndex(i), 1, 0);
                graph.addEdge(getSecondIndex(i), 2*vertices+1, 2, 0); 
            }
            for (int i=0; i<points.size(); i++) {
                Point point = points.get(i);
                for (int j=0; j<points.size(); j++) {
                    Point secondPoint = points.get(j);
                    if (point.isLower(secondPoint)) {
                        graph.addEdge(getFirstIndex(i), getSecondIndex(j), 1, point.getDistance(secondPoint)); 
                    }
                }
            }
            return graph;
        }
    }
    
    
    class Graph {
        
        int vertices;
        boolean found[];
        double cap[][], flow[][], cost[][], dist[], pi[];
        int prev[];
        int s = 0, t;
        
        static double INF = Double.MAX_VALUE/2 - 1;

        public Graph(int vertices) {
            this.vertices = vertices;
            cap = new double[vertices][vertices];
            flow = new double[vertices][vertices];
            cost = new double[vertices][vertices];
            prev = new int[vertices];
            dist = new double[vertices+1];
            pi = new double[vertices];
            found = new boolean[vertices];
            t = vertices-1;
        }
        
        
        public void addEdge(int from, int to, int capacity, double cost) {
            this.cap[from][to] = capacity;
            this.cost[from][to] = cost;
        }
        
        boolean search(int s, int t) {
            Arrays.fill(found, false);
            Arrays.fill(dist, INF);
            dist[s] = 0;

            while (s != vertices) {
                int best = vertices;
                found[s] = true;
                for (int k = 0; k < vertices; k++) {
                if (found[k]) continue;
                if (flow[k][s] != 0) {
                    double val = dist[s] + pi[s] - pi[k] - cost[k][s];
                    if (dist[k] > val) {
                    dist[k] = val;
                    prev[k] = s;
                    }
                }
                if (flow[s][k] < cap[s][k]) {
                    double val = dist[s] + pi[s] - pi[k] + cost[s][k];
                    if (dist[k] > val) {
                    dist[k] = val;
                    prev[k] = s;
                    }
                }
                
                if (dist[k] < dist[best]) best = k;
                }
                s = best;
            }
            for (int k = 0; k < vertices; k++)
                pi[k] = Math.min(pi[k] + dist[k], INF);
            return found[t];
            }
            
            
            double[] getMaxFlow() {
            
            double totflow = 0, totcost = 0;
            while (search(s, t)) {
                double amt = INF;
                for (int x = t; x != s; x = prev[x])
                amt = Math.min(amt, flow[x][prev[x]] != 0 ? flow[x][prev[x]] :
                               cap[prev[x]][x] - flow[prev[x]][x]);
                for (int x = t; x != s; x = prev[x]) {
                if (flow[x][prev[x]] != 0) {
                    flow[x][prev[x]] -= amt;
                    totcost -= amt * cost[x][prev[x]];
                } else {
                    flow[prev[x]][x] += amt;
                    totcost += amt * cost[prev[x]][x];
                }
                }
                totflow += amt;
            }
            
            return new double[]{ totflow, totcost };
            }
        
    }
    
    
class SupaGraph {
    boolean found[];
    int N, prev[];
    double cap[][], flow[][], cost[][], dist[], pi[];
    
    static final double INF = Double.MAX_VALUE / 2 - 1;
    
    boolean search(int s, int t) {
    Arrays.fill(found, false);
    Arrays.fill(dist, INF);
    dist[s] = 0;

    while (s != N) {
        int best = N;
        found[s] = true;
        for (int k = 0; k < N; k++) {
        if (found[k]) continue;
        if (flow[k][s] != 0) {
            double val = dist[s] + pi[s] - pi[k] - cost[k][s];
            if (dist[k] > val) {
            dist[k] = val;
            prev[k] = s;
            }
        }
        if (flow[s][k] < cap[s][k]) {
            double val = dist[s] + pi[s] - pi[k] + cost[s][k];
            if (dist[k] > val) {
            dist[k] = val;
            prev[k] = s;
            }
        }
        
        if (dist[k] < dist[best]) best = k;
        }
        s = best;
    }
    for (int k = 0; k < N; k++)
        pi[k] = Math.min(pi[k] + dist[k], INF);
    return found[t];
    }
    
    
    double[] getMaxFlow(double cap[][], double cost[][], int s, int t) {
    this.cap = cap;
    this.cost = cost;
    
    N = cap.length;
        found = new boolean[N];
        flow = new double[N][N];
        dist = new double[N+1];
        prev = new int[N];
        pi = new double[N];
    
    double totflow = 0, totcost = 0;
    while (search(s, t)) {
        double amt = INF;
        for (int x = t; x != s; x = prev[x])
        amt = Math.min(amt, flow[x][prev[x]] != 0 ? flow[x][prev[x]] :
                       cap[prev[x]][x] - flow[prev[x]][x]);
        for (int x = t; x != s; x = prev[x]) {
        if (flow[x][prev[x]] != 0) {
            flow[x][prev[x]] -= amt;
            totcost -= amt * cost[x][prev[x]];
        } else {
            flow[prev[x]][x] += amt;
            totcost += amt * cost[prev[x]][x];
        }
        }
        totflow += amt;
    }
    
    return new double[]{ totflow, totcost };
    }
}