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.*;
public class E277 {
public static void main(String[] args)
{
    Scanner input = new Scanner(System.in);
    int n = input.nextInt();
    int[] xs = new int[n], ys = new int[n];
    for(int i = 0; i<n; i++)
    {
        xs[i] = input.nextInt();
        ys[i] = input.nextInt();
    }
    MinCostFlow mcf = new MinCostFlow(2*n);
    for(int i = 0; i<n; i++)
    {
        mcf.add(mcf.source, i, 2, 0);
        mcf.add(i+n,  mcf.sink, 1, 0);
        for(int j = 0; j<n; j++)
        {
            if(ys[j] < ys[i])
            {
                mcf.add(i, j+n, 1, Math.sqrt((xs[i] - xs[j]) * (xs[i] - xs[j]) + (ys[i] - ys[j]) * (ys[i] - ys[j])));
            }
        }
    }
    double[] res = mcf.minCostMaxFlow();
    //System.out.println(res[0]+" "+res[1]);
    if(res[0] != n-1) System.out.println(-1);
    else System.out.println(res[1]);
}
public static class MinCostFlow
{
    public static final long INF1 = 1000000000;
    public static final long INF2 = 100000000;
    
    public ArrayList<Edge>[] adj;
    public int source;
    public int sink;
    public int metaSource;
    public int metaSink;
    public Edge[] prev;
    public long[] width;
    public double[] pi;
    
    public MinCostFlow(int n)
    {
        source = n++;
        sink = n++;
        metaSource = n++;
        metaSink = n++;
        
        adj = new ArrayList[n];
        for(int i = 0; i < adj.length; i++)
        {
            adj[i] = new ArrayList<Edge>();
        }
    }
    
    public Edge add(int a, int b, long cap, double c)
    {
        Edge e1 = new Edge(a, b, cap, c);
        Edge e2 = new Edge(b, a, 0, -c);
        e1.rev = e2;
        e2.rev = e1;
        adj[a].add(e1);
        adj[b].add(e2);
        
        return e1;
    }
    
    public double[] minCostMaxFlowNegCycles()
    {
        Edge flow = add(sink, source, INF1, -INF2);
        
        double cost = minCostFlow();
        
        return new double[] {INF1 - flow.capacity, cost + INF2 * (INF1 - flow.capacity)};
    }
    
    public double minCostFlow()
    {
        long result = 0;
        long[] val = new long[adj.length];
        for(int i = 0; i < adj.length; i++)
        {
            for(Edge e : adj[i])
            {
                if(e.capacity > 0 && e.cost < 0)
                {
                    result += e.capacity * e.cost;
                    val[e.start] -= e.capacity;
                    val[e.end] += e.capacity;
                    e.rev.capacity = e.capacity;
                    e.capacity = 0;
                }
            }
        }
        
        for(int i = 0; i < val.length; i++)
        {
            if(val[i] > 0)
            {
                add(metaSource, i, val[i], 0);
            }
            else if(val[i] < 0)
            {
                add(i, metaSink, -val[i], 0);
            }
        }
        
        source = metaSource;
        sink = metaSink;
        
        return result + minCostMaxFlow()[1];
    }
    
    public double[] minCostMaxFlow()
    {
        long flow = 0;
        double cost = 0;
        
        getPotential();
        
        while(findPath())
        {
            flow += width[sink];
            cost += update();
        }
        
        return new double[] {flow, cost};
    }
    
    public void getPotential()
    {
        pi = new double[adj.length];
        Arrays.fill(pi, INF1);
        pi[source] = 0;
        
        for(int i = 0; i < adj.length - 1; i++)
        {
            boolean update = false;
            for(int j = 0; j < adj.length; j++)
            {
                for(Edge e : adj[j])
                {
                    if(e.capacity > 0 && pi[e.start] + e.cost < pi[e.end])
                    {
                        pi[e.end] = pi[e.start] + e.cost;
                        update = true;
                    }
                }
            }
            
            if(!update)
            {
                break;
            }
        }
    }
    
    public boolean findPath()
    {
        double[] dist = new double[adj.length];
        Arrays.fill(dist, INF1);
        dist[source] = 0;
        
        prev = new Edge[adj.length];
        
        width = new long[adj.length];
        Arrays.fill(width, INF1);
        
        PriorityQueue<Node> pq = new PriorityQueue<Node>();
        pq.add(new Node(source, 0));
        
        while(pq.size() > 0)
        {
            Node node = pq.poll();
            
            if(node.dist == dist[node.index])
            {
                for(Edge e : adj[node.index])
                {
                    double newDist = dist[node.index] + e.cost + pi[e.start] - pi[e.end];
                    if(e.capacity > 0 && newDist < dist[e.end])
                    {
                        dist[e.end] = newDist;
                        prev[e.end] = e;
                        width[e.end] = Math.min(width[node.index], e.capacity);
                        pq.add(new Node(e.end, newDist));
                    }
                }
            }
        }
        
        for(int i = 0; i < pi.length; i++)
        {
            pi[i] += dist[i];
        }
        
        return (dist[sink] < INF1);
    }
    
    public double update()
    {
        int node = sink;
        double current = 0;
        while(prev[node] != null)
        {
            prev[node].capacity -= width[sink];
            prev[node].rev.capacity += width[sink];
            current += width[sink] * prev[node].cost;
            node = prev[node].start;
        }
        
        return current;
    }
    
    static class Edge
    {
        int start;
        int end;
        long capacity;
        double cost;
        Edge rev;
        
        public Edge(int s, int e, long cap, double c)
        {
            start = s;
            end = e;
            capacity = cap;
            cost = c;
        }
    }
    
    static class Node implements Comparable<Node>
    {
        int index;
        double dist;
        
        public Node(int i, double d)
        {
            index = i;
            dist = d;
        }
        
        public int compareTo(Node o)
        {
            return Double.compare(dist, o.dist);
        }
    }
}
}