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 CodeforcesE277 {
	public static void main(String[] args){
		Scanner br = new Scanner(System.in);
		int n = br.nextInt();
		
		MinCostFlow mcf = new MinCostFlow(2*n);
		
		Point[] ps = new Point[n];
		for(int i = 0;i<n;i++){
			ps[i] = new Point(br.nextInt(), br.nextInt());
			
		}
		Arrays.sort(ps);
		for(int i = 0;i<n;i++){
			int count = 0;
			mcf.add(mcf.source, i, 2, 0);
			mcf.add(i+n, mcf.sink, 1, 0);
			for(int j = i+1;j<n;j++){
				if(ps[i].y > ps[j].y){
					count++;
					mcf.add(i, j+n, 1, ps[i].dist(ps[j]));
				}
			}
		}
		double[] res = mcf.minCostMaxFlow();
		if(res[0] != n-1){
			System.out.println(-1);
		}
		else{
			System.out.println(res[1]);
		}
	}
	public static class Point implements Comparable<Point>{
		int x, y;
		public Point(int a, int b){
			x = a;
			y = b;
		}
		public int compareTo(Point o){
			return o.y-y;
		}
		public double dist(Point o){
			return Math.sqrt((x-o.x)*(x-o.x) + (y-o.y)*(y-o.y));
		}
	}
	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()
		{
			double 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);
				}
			}
			//add(sink, source, 1000, 0);
			source = metaSource;
			sink = metaSink;
			return result + minCostMaxFlow()[1];
		}
		
		public double[] minCostMaxFlow()
		{
			double 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);
			}
		}
	}
}