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.*;
import java.io.*;

public class Main {
	static int[] x, y;
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		
		int n = Integer.parseInt(br.readLine());
		x = new int[n];
		y = new int[n];
		
		for (int i = 0; i < n; ++i) {
			String[] sp = br.readLine().trim().split("\\s+");
			x[i] = Integer.parseInt(sp[0]);
			y[i] = Integer.parseInt(sp[1]);
		}
		
		// check first if root is ok
		int maxY = Integer.MIN_VALUE;
		for (int Y : y) {
			maxY = Math.max(maxY, Y);
		}
		int maxCount = 0;
		int root = 0;
		for (int i = 0; i < n; ++i) {
			if (y[i] == maxY) {
				root = i;
				maxCount++;
			}
		}
		if (maxCount > 1) {
			System.out.println("-1");
			return;
		}
		
		int gSize = n * 2 + 2;
		List<Edge>[] g = createGraph(gSize);
		
		int source = gSize - 2;
		int sink = gSize - 1;
				
		for (int i = 0; i < n; ++i) {
			addEdge(g, source, i, (i == root ? 2 : 2), 0);
			addEdge(g, i + n, sink, 1, 0);
		}
		
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				if (y[i] > y[j]) {
					addEdge(g, i, j + n, 1, Math.hypot(x[i] - x[j], y[i] - y[j]));
				}
			}
		}
		
		double c = minCostFlow(g, source, sink, n - 1);
		if (c == -1)
			System.out.println("-1");
		else
			System.out.printf("%.15f\n", c);
		
	}
	
	
	static List<Edge>[] createGraph(int n) {
		List<Edge>[] graph = new List[n];
		for (int i = 0; i < n; ++i)
			graph[i] = new ArrayList<>();
		return graph;
	}
	
	static void addEdge(List<Edge>[] g, int s, int t, int cap, double cost) {
		g[s].add(new Edge(t, cap, cost, g[t].size()));
		g[t].add(new Edge(s, 0, -cost, g[s].size() - 1));
	}
	
	static void bf(List<Edge>[] g, int s, double[] d) {
		int n = g.length;
		Arrays.fill(d, 0, n, Integer.MAX_VALUE);
		d[s] = 0;
		boolean[] inqueue = new boolean[n];
		int[] q = new int[n];
		int qt = 0;
		q[qt++] = s;
		for (int qh = 0; (qh - qt) % n != 0; qh++) {
			int u = q[qh % n];
			inqueue[u] = false;
			for (int i = 0; i < g[u].size(); i++) {
				Edge e = g[u].get(i);
				if (e.cap <= e.f) continue;
				int v = e.to;
				double ndist = d[u] + e.cost;
				if (d[v] > ndist) {
					d[v] = ndist;
					if (!inqueue[v]) {
						inqueue[v] = true;
						q[qt++ % n] = v;
					}
				}
			}
		}
	}
	
	static double minCostFlow(List<Edge>[] g, int s, int t, int maxf) {
		int n = g.length;
		double[] prio = new double[n];
		int[] curf = new int[n];
		int[] prevedge = new int[n];
		int[] prevnode = new int[n];
		double[] pot = new double[n];
		bf(g, s, pot);
		// System.out.println(Arrays.toString(pot));
		int flow = 0;
		double flowCost = 0;
		
		while (flow < maxf) {
			Queue<Pair> q = new PriorityQueue<Pair>();
			q.add(new Pair(s, 0));
			Arrays.fill(prio, 0, n, Integer.MAX_VALUE);
			prio[s] = 0;
			curf[s] = Integer.MAX_VALUE;
			while (!q.isEmpty()) {
				Pair cur = q.remove();
				double d = cur.value;
				int u = cur.id;
				if (Math.abs(d - prio[u]) > 1e-7) continue;
				for (int i = 0; i < g[u].size(); ++i) {
					Edge e = g[u].get(i);
					int v = e.to;
					if (e.cap <= e.f) continue;
					double nprio = prio[u] + e.cost + pot[u] - pot[v];
					// System.out.println(v + " " + nprio);
					if (prio[v] > nprio) {
						prio[v] = nprio;
						q.add(new Pair(v, nprio));
						prevnode[v] = u;
						prevedge[v] = i;
						curf[v] = Math.min(curf[u], e.cap - e.f);
					}
				}
			}
			if (prio[t] == Integer.MAX_VALUE) break;
			for (int i = 0; i < n; ++i)
				pot[i] += prio[i];
			int df = Math.min(curf[t], maxf - flow);
			flow += df;
			for (int v = t; v != s; v = prevnode[v]) {
				Edge e = g[prevnode[v]].get(prevedge[v]);
				e.f += df; g[v].get(e.rev).f -= df;
				flowCost += df * e.cost;
			}
		}
		// System.out.println(flow);
		if (flow != maxf)
			return -1;
		// return new int[] {flow, flowCost};
		return flowCost;
	}
	
}

class Pair implements Comparable<Pair> {
	public double value;
	public int id;
	public Pair(int id, double value) {
		this.id = id;
		this.value = value;
	}
	public int compareTo(Pair p) {
		return Double.compare(value, p.value);
	}
}

class Edge {
	int to, f=0, cap, rev;
	double cost;
	public Edge(int v, int cap, double cost, int rev) {
		this.to = v;
		this.cap = cap;
		this.cost = cost;
		this.rev = rev;
	}
}