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 {
    
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        // PrintWriter pw = new PrintWriter(new BufferedWriter(OutputStreamWriter(System.out)));
        
        int n = Integer.parseInt(br.readLine());
        int[] x = new int[n];
        int[] 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]);
        }
        
        int gn = n * 2 + 2;
        int source = gn - 2;
        int sink = gn - 1;
        
        List<Edge>[] g = createGraph(gn);
        
        for (int i = 0; i < n; ++i) {
            addEdge(g, source, i, 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]));
                }
            }
        }
        
        Pair max = minCostFlow(g, source, sink, Integer.MAX_VALUE);
                
        if (max.first != n - 1)
            System.out.println("-1");
        
        else
            System.out.println(max.second);
        
        // pw.close();
    }
    
    
    static class Edge {
       int to, f, cap, rev; double cost;
       Edge(int v, int cap, double cost, int rev) {
          this.to = v; this.cap = cap;
          this.cost = cost; this.rev = rev;
       }
    }
    static class Pair implements Comparable<Pair> {
       int first; double second;
       Pair(int first, double second) {
        this.first = first; this.second = second;
       }
       public int compareTo(Pair p) { return Double.compare(second, p.second); }
    }
    public 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;
    }
    public 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, Double.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; }}}}
    }

    public static Pair minCostFlow(List<Edge>[] g, 
    int s, int t, int maxf) {
       int n = g.length;
       double[] prio, pot; // initialize double[n]
       int[] curf,prevedge,prevnode; // initialize int[n]
       
       prio = new double[n];
       pot = new double[n];
       curf = new int[n];
       prevedge = new int[n];
       prevnode = new int[n];
       
       bf(g, s, pot); // skip if edge costs are non-negative
       int flow = 0; double flowCost = 0;
       while(flow < maxf) {
          Queue<Pair> q = new PriorityQueue<Pair>();
          q.add(new Pair(s, 0));
          Arrays.fill(prio, Double.MAX_VALUE);
          prio[s] = 0;
          curf[s] = Integer.MAX_VALUE;
          while(!q.isEmpty()) {
             Pair cur = q.remove();
             int u = cur.first;
             double d = cur.second;
             if(d != prio[u]) 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];
                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] == Double.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; }}
       return new Pair(flow, flowCost);
    }


}