#include <bits/stdc++.h>
using namespace std;
struct edge {
  long long int to, flow, cap;
  double cost;
  long long int rev;
};
struct MinCostMaxFlow {
  long long int nodes;
  vector<long long int> curflow, prevedge, prevnode, q;
  vector<double> pot, prio;
  vector<bool> inqueue;
  vector<vector<edge> > graph;
  MinCostMaxFlow() {}
  MinCostMaxFlow(long long int n)
      : nodes(n),
        prio(n, 0),
        curflow(n, 0),
        prevedge(n, 0),
        prevnode(n, 0),
        q(n, 0),
        pot(n, 0),
        inqueue(n, 0),
        graph(n) {}
  void addEdge(long long int source, long long int to, long long int capacity,
               double cost) {
    edge a = {to, 0, capacity, cost, (long long int)graph[to].size()};
    edge b = {source, 0, 0, -cost, (long long int)graph[source].size()};
    graph[source].push_back(a);
    graph[to].push_back(b);
  }
  void bellman_ford(long long int source, vector<double> &dist) {
    fill(dist.begin(), dist.end(), 1e9);
    dist[source] = 0;
    long long int qt = 0;
    q[qt++] = source;
    for (long long int qh = 0; (qh - qt) % nodes != 0; qh++) {
      long long int u = q[qh % nodes];
      inqueue[u] = false;
      for (auto &e : graph[u]) {
        if (e.flow >= e.cap) continue;
        long long int v = e.to;
        double newDist = dist[u] + e.cost;
        if (dist[v] > newDist) {
          dist[v] = newDist;
          if (!inqueue[v]) {
            inqueue[v] = true;
            q[qt++ % nodes] = v;
          }
        }
      }
    }
  }
  pair<long long int, double> minCostFlow(long long int source,
                                          long long int dest,
                                          long long int maxflow) {
    bellman_ford(source, pot);
    long long int flow = 0;
    double flow_cost = 0;
    while (flow < maxflow) {
      priority_queue<pair<double, long long int>,
                     vector<pair<double, long long int> >,
                     greater<pair<double, long long int> > >
          q;
      q.push({0, source});
      fill(prio.begin(), prio.end(), INT_MAX);
      prio[source] = 0;
      curflow[source] = INT_MAX;
      while (!q.empty()) {
        double d = q.top().first;
        long long int u = q.top().second;
        q.pop();
        if (d != prio[u]) continue;
        for (long long int i = 0; i < graph[u].size(); i++) {
          edge &e = graph[u][i];
          long long int v = e.to;
          if (e.flow >= e.cap) continue;
          double newPrio = prio[u] + e.cost + pot[u] - pot[v];
          if (prio[v] > newPrio) {
            prio[v] = newPrio;
            q.push({newPrio, v});
            prevnode[v] = u;
            prevedge[v] = i;
            curflow[v] = min(curflow[u], e.cap - e.flow);
          }
        }
      }
      if (prio[dest] == INT_MAX) break;
      for (long long int i = 0; i < nodes; i++) pot[i] += prio[i];
      long long int df = min(curflow[dest], maxflow - flow);
      flow += df;
      for (long long int v = dest; v != source; v = prevnode[v]) {
        edge &e = graph[prevnode[v]][prevedge[v]];
        e.flow += df;
        graph[v][e.rev].flow -= df;
        flow_cost += df * e.cost;
      }
    }
    return {flow, flow_cost};
  }
};
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  vector<pair<long long int, long long int> > nos;
  cin >> n;
  MinCostMaxFlow tee(2 * n + 4);
  for (long long int i = 1; i <= n; i++) {
    long long int x, y;
    cin >> x >> y;
    nos.push_back(make_pair(x, y));
    tee.addEdge(0, i, 2, 0);
    tee.addEdge(i + n, 2 * n + 1, 1, 0);
  }
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 1; j <= n; j++) {
      if (nos[i - 1].second > nos[j - 1].second) {
        tee.addEdge(i, n + j, 1,
                    sqrtl((nos[i - 1].second - nos[j - 1].second) *
                              (nos[i - 1].second - nos[j - 1].second) +
                          (nos[i - 1].first - nos[j - 1].first) *
                              (nos[i - 1].first - nos[j - 1].first)));
      }
    }
  }
  auto it = tee.minCostFlow(0, 2 * n + 1, 1000000007);
  if (it.first != n - 1) {
    cout << -1;
  } else {
    cout << fixed << setprecision(10) << it.second;
  }
  return 0;
}

### Prompt

Please formulate a cpp solution to the following 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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct edge {
  long long int to, flow, cap;
  double cost;
  long long int rev;
};
struct MinCostMaxFlow {
  long long int nodes;
  vector<long long int> curflow, prevedge, prevnode, q;
  vector<double> pot, prio;
  vector<bool> inqueue;
  vector<vector<edge> > graph;
  MinCostMaxFlow() {}
  MinCostMaxFlow(long long int n)
      : nodes(n),
        prio(n, 0),
        curflow(n, 0),
        prevedge(n, 0),
        prevnode(n, 0),
        q(n, 0),
        pot(n, 0),
        inqueue(n, 0),
        graph(n) {}
  void addEdge(long long int source, long long int to, long long int capacity,
               double cost) {
    edge a = {to, 0, capacity, cost, (long long int)graph[to].size()};
    edge b = {source, 0, 0, -cost, (long long int)graph[source].size()};
    graph[source].push_back(a);
    graph[to].push_back(b);
  }
  void bellman_ford(long long int source, vector<double> &dist) {
    fill(dist.begin(), dist.end(), 1e9);
    dist[source] = 0;
    long long int qt = 0;
    q[qt++] = source;
    for (long long int qh = 0; (qh - qt) % nodes != 0; qh++) {
      long long int u = q[qh % nodes];
      inqueue[u] = false;
      for (auto &e : graph[u]) {
        if (e.flow >= e.cap) continue;
        long long int v = e.to;
        double newDist = dist[u] + e.cost;
        if (dist[v] > newDist) {
          dist[v] = newDist;
          if (!inqueue[v]) {
            inqueue[v] = true;
            q[qt++ % nodes] = v;
          }
        }
      }
    }
  }
  pair<long long int, double> minCostFlow(long long int source,
                                          long long int dest,
                                          long long int maxflow) {
    bellman_ford(source, pot);
    long long int flow = 0;
    double flow_cost = 0;
    while (flow < maxflow) {
      priority_queue<pair<double, long long int>,
                     vector<pair<double, long long int> >,
                     greater<pair<double, long long int> > >
          q;
      q.push({0, source});
      fill(prio.begin(), prio.end(), INT_MAX);
      prio[source] = 0;
      curflow[source] = INT_MAX;
      while (!q.empty()) {
        double d = q.top().first;
        long long int u = q.top().second;
        q.pop();
        if (d != prio[u]) continue;
        for (long long int i = 0; i < graph[u].size(); i++) {
          edge &e = graph[u][i];
          long long int v = e.to;
          if (e.flow >= e.cap) continue;
          double newPrio = prio[u] + e.cost + pot[u] - pot[v];
          if (prio[v] > newPrio) {
            prio[v] = newPrio;
            q.push({newPrio, v});
            prevnode[v] = u;
            prevedge[v] = i;
            curflow[v] = min(curflow[u], e.cap - e.flow);
          }
        }
      }
      if (prio[dest] == INT_MAX) break;
      for (long long int i = 0; i < nodes; i++) pot[i] += prio[i];
      long long int df = min(curflow[dest], maxflow - flow);
      flow += df;
      for (long long int v = dest; v != source; v = prevnode[v]) {
        edge &e = graph[prevnode[v]][prevedge[v]];
        e.flow += df;
        graph[v][e.rev].flow -= df;
        flow_cost += df * e.cost;
      }
    }
    return {flow, flow_cost};
  }
};
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  vector<pair<long long int, long long int> > nos;
  cin >> n;
  MinCostMaxFlow tee(2 * n + 4);
  for (long long int i = 1; i <= n; i++) {
    long long int x, y;
    cin >> x >> y;
    nos.push_back(make_pair(x, y));
    tee.addEdge(0, i, 2, 0);
    tee.addEdge(i + n, 2 * n + 1, 1, 0);
  }
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 1; j <= n; j++) {
      if (nos[i - 1].second > nos[j - 1].second) {
        tee.addEdge(i, n + j, 1,
                    sqrtl((nos[i - 1].second - nos[j - 1].second) *
                              (nos[i - 1].second - nos[j - 1].second) +
                          (nos[i - 1].first - nos[j - 1].first) *
                              (nos[i - 1].first - nos[j - 1].first)));
      }
    }
  }
  auto it = tee.minCostFlow(0, 2 * n + 1, 1000000007);
  if (it.first != n - 1) {
    cout << -1;
  } else {
    cout << fixed << setprecision(10) << it.second;
  }
  return 0;
}

```