#include <bits/stdc++.h>
using namespace std;
const double oo = (double)(1ll << 50ll);
const int MAXV = 1000;
const int MAXE = 1000010;
struct edge {
  int dest;
  int cap, flow;
  double cost;
  int next;
  edge() {}
  edge(int dest, int cap, double cost, int next)
      : dest(dest), cap(cap), cost(cost), next(next) {
    flow = 0;
  }
};
int nodes, source, sink;
int size;
edge g[MAXE];
int first[MAXV];
int nLast[MAXV];
int eLast[MAXV];
double cst[MAXV];
void initialize_MFMC(int __nodes, int __source, int __sink) {
  size = 0;
  nodes = __nodes;
  source = __source;
  sink = __sink;
  for (int i = 0; i < nodes; i++) first[i] = -1;
}
void addEdge(int u, int v, int c, double cost) {
  g[size] = edge(v, c, +cost, first[u]);
  first[u] = size++;
  g[size] = edge(u, 0, -cost, first[v]);
  first[v] = size++;
}
pair<int, double> maxFlowMinCost(int F) {
  int flow = 0;
  double flowCost = 0;
  while (flow < F) {
    priority_queue<pair<double, int> > Q;
    for (int i = 0; i < nodes; i++) cst[i] = oo;
    cst[source] = 0;
    Q.push(pair<double, int>(0, source));
    while (!Q.empty()) {
      int u = Q.top().second;
      double c = -Q.top().first;
      Q.pop();
      if (u == sink) break;
      for (int k = first[u]; k != -1; k = g[k].next) {
        int newU = g[k].dest;
        double newC = g[k].cost + c;
        if (g[k].cap > g[k].flow && newC < cst[newU]) {
          cst[newU] = newC;
          nLast[newU] = u;
          eLast[newU] = k;
          Q.push(make_pair(-newC, newU));
        }
      }
    }
    if (cst[sink] == oo) break;
    int push = (1 << 29);
    for (int u = sink; u != source; u = nLast[u])
      push = min(push, g[eLast[u]].cap - g[eLast[u]].flow);
    if (flow + push > F) push = F - flow;
    flow += push;
    flowCost += cst[sink] * (double)push;
    for (int u = sink; u != source; u = nLast[u]) {
      g[eLast[u]].flow += push;
      g[eLast[u] ^ 1].flow -= push;
    }
  }
  return pair<int, double>(flow, flowCost);
}
int x[MAXV], y[MAXV];
double dii(int i, int j) {
  return sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
  }
  initialize_MFMC(2 + 2 * n, 0, 1);
  for (int i = 0; i < n; i++) {
    addEdge(0, 2 + i, 2, 0);
    for (int j = 0; j < n; j++) {
      if (y[i] > y[j]) {
        addEdge(2 + i, 2 + n + j, 1, dii(i, j));
      }
    }
    addEdge(2 + n + i, 1, 1, 0);
  }
  pair<int, double> mxf = maxFlowMinCost(n - 1);
  if (mxf.first != n - 1) {
    cout << "-1\n";
  } else {
    cout.precision(10);
    cout << fixed << mxf.second << '\n';
  }
}

### Prompt

Please provide a cpp coded solution to the problem described below:

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double oo = (double)(1ll << 50ll);
const int MAXV = 1000;
const int MAXE = 1000010;
struct edge {
  int dest;
  int cap, flow;
  double cost;
  int next;
  edge() {}
  edge(int dest, int cap, double cost, int next)
      : dest(dest), cap(cap), cost(cost), next(next) {
    flow = 0;
  }
};
int nodes, source, sink;
int size;
edge g[MAXE];
int first[MAXV];
int nLast[MAXV];
int eLast[MAXV];
double cst[MAXV];
void initialize_MFMC(int __nodes, int __source, int __sink) {
  size = 0;
  nodes = __nodes;
  source = __source;
  sink = __sink;
  for (int i = 0; i < nodes; i++) first[i] = -1;
}
void addEdge(int u, int v, int c, double cost) {
  g[size] = edge(v, c, +cost, first[u]);
  first[u] = size++;
  g[size] = edge(u, 0, -cost, first[v]);
  first[v] = size++;
}
pair<int, double> maxFlowMinCost(int F) {
  int flow = 0;
  double flowCost = 0;
  while (flow < F) {
    priority_queue<pair<double, int> > Q;
    for (int i = 0; i < nodes; i++) cst[i] = oo;
    cst[source] = 0;
    Q.push(pair<double, int>(0, source));
    while (!Q.empty()) {
      int u = Q.top().second;
      double c = -Q.top().first;
      Q.pop();
      if (u == sink) break;
      for (int k = first[u]; k != -1; k = g[k].next) {
        int newU = g[k].dest;
        double newC = g[k].cost + c;
        if (g[k].cap > g[k].flow && newC < cst[newU]) {
          cst[newU] = newC;
          nLast[newU] = u;
          eLast[newU] = k;
          Q.push(make_pair(-newC, newU));
        }
      }
    }
    if (cst[sink] == oo) break;
    int push = (1 << 29);
    for (int u = sink; u != source; u = nLast[u])
      push = min(push, g[eLast[u]].cap - g[eLast[u]].flow);
    if (flow + push > F) push = F - flow;
    flow += push;
    flowCost += cst[sink] * (double)push;
    for (int u = sink; u != source; u = nLast[u]) {
      g[eLast[u]].flow += push;
      g[eLast[u] ^ 1].flow -= push;
    }
  }
  return pair<int, double>(flow, flowCost);
}
int x[MAXV], y[MAXV];
double dii(int i, int j) {
  return sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
  }
  initialize_MFMC(2 + 2 * n, 0, 1);
  for (int i = 0; i < n; i++) {
    addEdge(0, 2 + i, 2, 0);
    for (int j = 0; j < n; j++) {
      if (y[i] > y[j]) {
        addEdge(2 + i, 2 + n + j, 1, dii(i, j));
      }
    }
    addEdge(2 + n + i, 1, 1, 0);
  }
  pair<int, double> mxf = maxFlowMinCost(n - 1);
  if (mxf.first != n - 1) {
    cout << "-1\n";
  } else {
    cout.precision(10);
    cout << fixed << mxf.second << '\n';
  }
}

```