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:
//package round170;
import java.awt.geom.Point2D;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.InputMismatchException;
import java.util.TreeSet;

public class E {
	InputStream is;
	PrintWriter out;
	String INPUT = "";
	
	void solve()
	{
		int n = ni();
		int[][] co = new int[n][];
		for(int i = 0;i < n;i++){
			co[i] = new int[]{ni(), ni()};
		}
		Arrays.sort(co, new Comparator<int[]>() {
			public int compare(int[] a, int[] b) {
				return -(a[1] - b[1]);
			}
		});
		
		// 0,n)
		// n,2n)
		// 2n
		// 2n+1
		int M = n*(n-1)/2+2*n;
		int[] from = new int[M];
		int[] to = new int[M];
		double[] c = new double[M];
		int[] a = new int[M];
		int p = 0;
		for(int i = 0;i < n;i++){
			for(int j = i+1;j < n;j++){
				if(co[i][1] > co[j][1]){
					from[p] = i; to[p] = n+j; c[p] = Point2D.distance(co[i][0], co[i][1], co[j][0], co[j][1]); a[p] = 1; p++;
				}
			}
			from[p] = 2*n; to[p] = i; c[p] = 0; a[p] = 2; p++;
			from[p] = n+i; to[p] = 2*n+1; c[p] = 0; a[p] = 1; p++;
		}
		
		int[][] g = new int[2*n+2][];
		double[][] cost = new double[2*n+2][];
		int[][] cap = new int[2*n+2][];
		packWDForFlow(g, cost, cap, from, to, c, a, p);
		
		double f = solveMinCostFlow(g, cost, cap, 2*n, 2*n+1, 2*n);
		if(A <= n+1){
			out.printf("%.12f\n", f);
		}else{
			out.println(-1);
		}
	}
	
	public static void packWDForFlow(int[][] g, double[][] cost, int[][] cap, int[] from, int[] to, double[] c, int[] w, int len)
	{
		int n = g.length;
		long[][] ing = new long[n][];
		int[] p = new int[n];
		for(int i = 0;i < len;i++)p[from[i]]++;
		for(int i = 0;i < n;i++){
			g[i] = new int[p[i]];
			ing[i] = new long[p[i]];
			cap[i] = new int[p[i]];
			cost[i] = new double[p[i]];
		}
		for(int i = 0;i < len;i++){
			ing[from[i]][--p[from[i]]] = ((long)to[i])<<32|i;
		}
		
		for(int i = 0;i < n;i++){
			int m = g[i].length;
			Arrays.sort(ing[i]);
			for(int j = 0;j < m;j++){
				g[i][j] = (int)(ing[i][j]>>32);
				cap[i][j] = w[(int)ing[i][j]];
				cost[i][j] = c[(int)ing[i][j]];
			}
		}
	}
	
	public static double solveMinCostFlow(int[][] g, double[][] cost, int[][] capacity, int src, int sink, int all)
	{
		int n = g.length;
		
		int[][] flow = new int[n][];
		for(int i = 0;i < n;i++) {
			flow[i] = new int[g[i].length];
		}
		
		// unweighted invgraph
		// 逆グラフのcurのi番目=nextのとき、順グラフでcurはnextの何番目にあるかを返す
		int[][][] ig = new int[n][][];
		{
			int[] p = new int[n];
			for(int i = 0;i < n;i++){
				for(int j = 0;j < g[i].length;j++)p[g[i][j]]++;
			}
			for(int i = 0;i < n;i++)ig[i] = new int[p[i]][2];
			for(int i = n-1;i >= 0;i--){
				for(int j = 0;j < g[i].length;j++){
					int u = --p[g[i][j]];
					ig[g[i][j]][u][0] = i;
					ig[g[i][j]][u][1] = j;
				}
			}
		}
		
		double mincost = 0;
		double[] pot = new double[n]; // ポテンシャル
		
		final double[] d = new double[n];
		TreeSet<Integer> q = new TreeSet<Integer>(new Comparator<Integer>(){
			public int compare(Integer a, Integer b)
			{
				if(d[a] - d[b] != 0)return (int)Math.signum(d[a] - d[b]);
				return a - b;
			}
		});
		while(all > 0){
			// src~sinkの最短路を探す
			int[] prev = new int[n];
			int[] myind = new int[n];
			Arrays.fill(prev, -1);
			Arrays.fill(d, Integer.MAX_VALUE / 2);
			d[src] = 0;
			q.clear();
			q.add(src);
			while(!q.isEmpty()){
				int cur = q.pollFirst();
				if(cur == sink)break;
				for(int i = 0;i < g[cur].length;i++) {
					int next = g[cur][i];
					if(capacity[cur][i] - flow[cur][i] > 0){
						double nd = d[cur] + cost[cur][i] + pot[cur] - pot[next];
						if(d[next] > nd){
							q.remove(next);
							d[next] = nd;
							prev[next] = cur;
							myind[next] = i;
							q.add(next);
						}
					}
				}
				for(int i = 0;i < ig[cur].length;i++) {
					int next = ig[cur][i][0];
					int cind = ig[cur][i][1];
					if(flow[next][cind] > 0){
						double nd = d[cur] - cost[next][cind] + pot[cur] - pot[next];
						if(d[next] > nd){
							q.remove(next);
							d[next] = nd;
							prev[next] = cur;
							myind[next] = -cind-1;
							q.add(next);
						}
					}
				}
			}
			
			if(prev[sink] == -1)break;
			
			int minflow = all;
			double sumcost = 0;
			for(int i = sink;i != src;i = prev[i]){
				if(myind[i] >= 0){
					minflow = Math.min(minflow, capacity[prev[i]][myind[i]] - flow[prev[i]][myind[i]]);
					sumcost += cost[prev[i]][myind[i]];
				}else{
					// cur->next
					// prev[i]->i
					// iが持ってる
					// ig[cur][j][0]=nextのときg[next][ig[cur][j][1]] = cur
					int ind = -myind[i]-1;
					minflow = Math.min(minflow, flow[i][ind]);
					sumcost -= cost[i][ind];
				}
			}
			
			mincost += minflow * sumcost;
			for(int i = sink;i != src;i = prev[i]){
				if(myind[i] >= 0){
					flow[prev[i]][myind[i]] += minflow;
				}else{
					int ind = -myind[i]-1;
					flow[i][ind] -= minflow;
				}
			}
			all -= minflow;
			for(int i = 0;i < n;i++){
				pot[i] += d[i];
			}
		}
		A = all;
		return mincost;
	}
	
	static int A;
	
	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);
		
		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}
	
	public static void main(String[] args) throws Exception { new E().run(); }
	
	private byte[] inbuf = new byte[1024];
	private int lenbuf = 0, ptrbuf = 0;
	
	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}
	
	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
	
	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }
	
	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	
	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}
	
	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}
	
	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}
	
	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}
		
		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}
		
		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}