#include <bits/stdc++.h>
using namespace std;
const int adj[8][2] = {{-1, 0},  {0, -1}, {1, 0}, {0, 1},
                       {-1, -1}, {-1, 1}, {1, 1}, {1, -1}};
const long long int LLINF = 9e18;
const int INF = 2e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1);
const int SIZE = 888;
int N;
struct points {
  double x, y;
} P[444];
struct edge {
  int v, f, c, u;
  unsigned long long int cost;
};
vector<edge> E[SIZE];
int lvl[SIZE], st[SIZE];
unsigned long long int cost[SIZE];
void init() {
  for (int i = 0; i < SIZE; i++) {
    E[i].clear();
  }
}
void addedge(int a, int b, int ca, int cb, unsigned long long int Cost) {
  edge A = {a, 0, ca, (int)E[a].size(), -Cost};
  edge B = {b, 0, cb, (int)E[b].size(), Cost};
  E[a].push_back(B);
  E[b].push_back(A);
}
double dist(points a, points b) {
  double x = a.x - b.x;
  double y = a.y - b.y;
  double ret = (x * x) + (y * y);
  ret = sqrt(ret);
  return ret;
}
void make_graph(int S, int T) {
  for (int i = 1; i <= N; i++) {
    addedge(S, i, 0, 2, 0);
    addedge(i + N, T, 0, 1, 0);
    for (int j = 1; j <= N; j++) {
      if (P[j].y < P[i].y) {
        double d = dist(P[i], P[j]);
        unsigned long long int l = d * 1e9;
        addedge(i, j + N, 0, 1, l);
      }
    }
  }
}
bool Dijkstra(int S, int T) {
  for (int i = 0; i < SIZE; i++) {
    cost[i] = 1e19;
    lvl[i] = -1;
  }
  priority_queue<pair<unsigned long long int, int> > pq;
  pq.push(make_pair(0, S));
  cost[S] = 0;
  lvl[S] = 0;
  while (!pq.empty()) {
    int indx = pq.top().second;
    unsigned long long int step = -pq.top().first;
    pq.pop();
    for (int i = 0; i < (int)E[indx].size(); i++) {
      edge &t = E[indx][i];
      int idx = t.v;
      if (cost[idx] > step + t.cost && t.c > t.f) {
        cost[idx] = step + t.cost;
        lvl[idx] = lvl[indx] + 1;
        pq.push(make_pair(-cost[idx], idx));
      }
    }
  }
  return lvl[T] >= 0;
}
int DFS(int indx, int T, int flow) {
  if (indx == T) return flow;
  for (int &i = st[indx]; i < (int)E[indx].size(); i++) {
    edge &t = E[indx][i];
    int idx = t.v;
    if (lvl[idx] == lvl[indx] + 1 && cost[idx] == cost[indx] + t.cost &&
        t.c > t.f) {
      int cur = min(flow, t.c - t.f);
      int ret = DFS(idx, T, cur);
      if (ret > 0) {
        t.f += ret;
        E[t.v][t.u].f -= ret;
        return ret;
      }
    }
  }
  return 0;
}
pair<unsigned long long int, int> MCMF(int S, int T) {
  pair<unsigned long long int, int> ret = make_pair(0, 0);
  while (Dijkstra(S, T)) {
    memset(st, 0, sizeof(st));
    while (int flow = DFS(S, T, INF)) {
      ret.first += cost[T];
      ret.second += flow;
    }
  }
  return ret;
}
int main() {
  int S = 0, T = SIZE - 1;
  init();
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%lf %lf", &P[i].x, &P[i].y);
  }
  make_graph(S, T);
  pair<unsigned long long int, int> ans = MCMF(S, T);
  if (ans.second == N - 1) {
    double res = (double)ans.first / (double)1e9;
    printf("%.9lf\n", res);
  } else
    printf("-1\n");
  return 0;
}

### Prompt

Your challenge is to write 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;
const int adj[8][2] = {{-1, 0},  {0, -1}, {1, 0}, {0, 1},
                       {-1, -1}, {-1, 1}, {1, 1}, {1, -1}};
const long long int LLINF = 9e18;
const int INF = 2e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1);
const int SIZE = 888;
int N;
struct points {
  double x, y;
} P[444];
struct edge {
  int v, f, c, u;
  unsigned long long int cost;
};
vector<edge> E[SIZE];
int lvl[SIZE], st[SIZE];
unsigned long long int cost[SIZE];
void init() {
  for (int i = 0; i < SIZE; i++) {
    E[i].clear();
  }
}
void addedge(int a, int b, int ca, int cb, unsigned long long int Cost) {
  edge A = {a, 0, ca, (int)E[a].size(), -Cost};
  edge B = {b, 0, cb, (int)E[b].size(), Cost};
  E[a].push_back(B);
  E[b].push_back(A);
}
double dist(points a, points b) {
  double x = a.x - b.x;
  double y = a.y - b.y;
  double ret = (x * x) + (y * y);
  ret = sqrt(ret);
  return ret;
}
void make_graph(int S, int T) {
  for (int i = 1; i <= N; i++) {
    addedge(S, i, 0, 2, 0);
    addedge(i + N, T, 0, 1, 0);
    for (int j = 1; j <= N; j++) {
      if (P[j].y < P[i].y) {
        double d = dist(P[i], P[j]);
        unsigned long long int l = d * 1e9;
        addedge(i, j + N, 0, 1, l);
      }
    }
  }
}
bool Dijkstra(int S, int T) {
  for (int i = 0; i < SIZE; i++) {
    cost[i] = 1e19;
    lvl[i] = -1;
  }
  priority_queue<pair<unsigned long long int, int> > pq;
  pq.push(make_pair(0, S));
  cost[S] = 0;
  lvl[S] = 0;
  while (!pq.empty()) {
    int indx = pq.top().second;
    unsigned long long int step = -pq.top().first;
    pq.pop();
    for (int i = 0; i < (int)E[indx].size(); i++) {
      edge &t = E[indx][i];
      int idx = t.v;
      if (cost[idx] > step + t.cost && t.c > t.f) {
        cost[idx] = step + t.cost;
        lvl[idx] = lvl[indx] + 1;
        pq.push(make_pair(-cost[idx], idx));
      }
    }
  }
  return lvl[T] >= 0;
}
int DFS(int indx, int T, int flow) {
  if (indx == T) return flow;
  for (int &i = st[indx]; i < (int)E[indx].size(); i++) {
    edge &t = E[indx][i];
    int idx = t.v;
    if (lvl[idx] == lvl[indx] + 1 && cost[idx] == cost[indx] + t.cost &&
        t.c > t.f) {
      int cur = min(flow, t.c - t.f);
      int ret = DFS(idx, T, cur);
      if (ret > 0) {
        t.f += ret;
        E[t.v][t.u].f -= ret;
        return ret;
      }
    }
  }
  return 0;
}
pair<unsigned long long int, int> MCMF(int S, int T) {
  pair<unsigned long long int, int> ret = make_pair(0, 0);
  while (Dijkstra(S, T)) {
    memset(st, 0, sizeof(st));
    while (int flow = DFS(S, T, INF)) {
      ret.first += cost[T];
      ret.second += flow;
    }
  }
  return ret;
}
int main() {
  int S = 0, T = SIZE - 1;
  init();
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%lf %lf", &P[i].x, &P[i].y);
  }
  make_graph(S, T);
  pair<unsigned long long int, int> ans = MCMF(S, T);
  if (ans.second == N - 1) {
    double res = (double)ans.first / (double)1e9;
    printf("%.9lf\n", res);
  } else
    printf("-1\n");
  return 0;
}

```