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 *y*<sub class="lower-index">*u*</sub> &gt; *y*<sub class="lower-index">*v*</sub>.

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.
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: *x*<sub class="lower-index">*i*</sub>, *y*<sub class="lower-index">*i*</sub> (|*x*<sub class="lower-index">*i*</sub>|, |*y*<sub class="lower-index">*i*</sub>| ≤ 10<sup class="upper-index">3</sup>) — coordinates of the nodes. It is guaranteed that all points are distinct.
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cmath>
using namespace std;
const int N = 1e5 + 1;
const int INF = 1e9 + 1;
struct node {
    int x,y;
    bool operator<(const node &tem)const{return y > tem.y;}
};
int hd[N],nxt[N << 2],to[N << 2],cap[N << 2],tot = 1,cur[N];
double val[N << 2],ans = 0,dis[N];
bool vis[N];
int s,t,n;
node p[N];
inline void add(const int u,const int v,const int z,const double k) {nxt[++tot] = hd[u],to[tot] = v,cap[tot] = z,val[tot] = k,hd[u] = tot;}
inline void adds(const int u,const int v,const int z,const double k) {add(u,v,z,k),add(v,u,0,-k);}
inline double calc(const int u,const int v) {return (double)sqrt((p[u].x - p[v].x) * (p[u].x - p[v].x) + (p[u].y - p[v].y) * (p[u].y - p[v].y));}
inline bool SPFA() {
    deque<int>Q;
    for(int i = 0; i <= t; i++) dis[i] = INF,vis[i] = false,cur[i] = hd[i];
    Q.push_back(s),dis[s] = 0,vis[s] = true;
    while(!Q.empty()) {
        int u = Q.front();Q.pop_front(),vis[u] = false;
        for(int eg = hd[u],v = to[eg]; eg; eg = nxt[eg],v = to[eg]) {
            if(cap[eg] && dis[v] > dis[u] + val[eg]) {
                dis[v] = dis[u] + val[eg];
                if(!vis[v]) Q.push_back(v),vis[v] = true;
            }
        }
    }
    return dis[t] != INF;
}
int dfs(const int u,const int flow) {
    if(u == t) return flow;
    vis[u] = true;
    int ret = 0;
    for(int eg = cur[u],v = to[eg]; eg && ret <= flow; eg = nxt[eg],v = to[eg]) {
        cur[u] = eg;
        if(!vis[v] && cap[eg] && dis[v] == dis[u] + val[eg]) {
            int k = dfs(v,min(cap[eg],flow - ret));
            if(!k) dis[v] = -1;
            ans += k * val[eg],cap[eg] -= k,cap[eg ^ 1] += k,ret += k;
        }
    }
    vis[u] = false;
    return ret;
}
int mcmf() {
    int sum = 0,f = 0;
    while(SPFA()) while(f = dfs(s,INF)) sum += f;
    return sum;
}
int main() {
    scanf("%d",&n);
    for(int i = 1; i <= n; i++) scanf("%d%d",&p[i].x,&p[i].y);
    sort(p + 1,p + 1 + n);
    s = 0,t = n << 1 | 1;
    for(int i = 1; i <= n; i++) adds(s,i,2,0),adds(i + n,t,1,0);
    for(int i = 1; i <= n; i++) for(int j = i + 1; j <= n; j++) if(p[i].y > p[j].y) adds(i,j + n,1,calc(i,j));
    if(mcmf() != n - 1) puts("-1");
    else printf("%.8lf\n",ans);
    return 0;
}