#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
template <typename T>
void etch(T V) {
  for (auto x : V) cout << x << ' ';
  cout << '\n';
}
vector<string> vec_splitter(string s) {
  s += ',';
  vector<string> res;
  while (!s.empty()) {
    res.push_back(s.substr(0, s.find(',')));
    s = s.substr(s.find(',') + 1);
  }
  return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
               __attribute__((unused)) long long int idx,
               __attribute__((unused)) long long int LINE_NUM) {
  cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, long long int idx, long long int LINE_NUM,
               Head H, Tail... T) {
  if (idx > 0)
    cerr << ", ";
  else
    cerr << "Line(" << LINE_NUM << ") ";
  stringstream ss;
  ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, LINE_NUM, T...);
}
const long long int MOD = 1e9 + 7;
const long long int MOD1 = 998244353;
const long long int N = 2e5 + 5;
const long long int INF = 1000111000111000111LL;
const long double EPS = 1e-12;
const long double PI = 3.141592653589793116;
struct Edge {
  long long int from, to, capacity;
  long double cost;
};
vector<vector<long long int>> adj, capacity;
vector<vector<long double>> cost;
void shortest_paths(long long int n, long long int v0, vector<long double> &d,
                    vector<long long int> &p) {
  d.assign(n, INF);
  d[v0] = 0.0l;
  vector<bool> inq(n, false);
  queue<long long int> q;
  q.push(v0);
  p.assign(n, -1);
  while (!q.empty()) {
    long long int u = q.front();
    q.pop();
    inq[u] = false;
    for (long long int v : adj[u]) {
      if (capacity[u][v] > 0 && d[v] > d[u] + cost[u][v]) {
        d[v] = d[u] + cost[u][v];
        p[v] = u;
        if (!inq[v]) {
          inq[v] = true;
          q.push(v);
        }
      }
    }
  }
}
long double min_cost_flow(long long int N, vector<Edge> edges, long long int K,
                          long long int s, long long int t) {
  adj.assign(N, vector<long long int>());
  cost.assign(N, vector<long double>(N, 0.0));
  capacity.assign(N, vector<long long int>(N, 0));
  for (Edge e : edges) {
    adj[e.from].push_back(e.to);
    adj[e.to].push_back(e.from);
    cost[e.from][e.to] = e.cost;
    cost[e.to][e.from] = -e.cost;
    capacity[e.from][e.to] = e.capacity;
  }
  long long int flow = 0;
  long double res = 0.0;
  vector<long long int> p;
  vector<long double> d;
  while (flow < K) {
    shortest_paths(N, s, d, p);
    if (d[t] == INF) break;
    long long int f = K - flow;
    long long int cur = t;
    while (cur != s) {
      f = min(f, capacity[p[cur]][cur]);
      cur = p[cur];
    }
    flow += f;
    res = res + f * d[t];
    cur = t;
    while (cur != s) {
      capacity[p[cur]][cur] -= f;
      capacity[cur][p[cur]] += f;
      cur = p[cur];
    }
  }
  if (flow < K)
    return -1.0l;
  else
    return res;
}
bool comp(pair<long long int, long long int> &a,
          pair<long long int, long long int> &b) {
  return a.second > b.second;
}
long double dist(pair<long long int, long long int> &a,
                 pair<long long int, long long int> &b) {
  return sqrtl(((a.first - b.first) * (a.first - b.first)) +
               ((a.second - b.second) * (a.second - b.second)));
}
int32_t main() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n;
  cin >> n;
  vector<pair<long long int, long long int>> v(n);
  for (auto &it : v) cin >> it.first >> it.second;
  sort((v).begin(), (v).end(), comp);
  vector<Edge> edges;
  for (long long int i = 0; i < n; i++) {
    Edge cur;
    cur.from = 0;
    cur.to = 2 * i + 1;
    cur.capacity = 2;
    cur.cost = 0.0l;
    edges.push_back(cur);
    for (long long int j = i + 1; j < n; j++) {
      if (v[i].second == v[j].second) continue;
      cur.from = 2 * i + 1;
      cur.to = 2 * j + 2;
      cur.capacity = 1;
      cur.cost = dist(v[i], v[j]);
      edges.push_back(cur);
    }
    cur.from = 2 * i + 2;
    cur.to = 2 * n + 1;
    cur.capacity = 1;
    cur.cost = 0.0l;
    edges.push_back(cur);
  }
  long double res = min_cost_flow(2 * n + 2, edges, n - 1, 0, 2 * n + 1);
  if (res < 0) return cout << "-1", 0;
  cout << fixed << setprecision(10) << res;
  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>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
template <typename T>
void etch(T V) {
  for (auto x : V) cout << x << ' ';
  cout << '\n';
}
vector<string> vec_splitter(string s) {
  s += ',';
  vector<string> res;
  while (!s.empty()) {
    res.push_back(s.substr(0, s.find(',')));
    s = s.substr(s.find(',') + 1);
  }
  return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
               __attribute__((unused)) long long int idx,
               __attribute__((unused)) long long int LINE_NUM) {
  cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, long long int idx, long long int LINE_NUM,
               Head H, Tail... T) {
  if (idx > 0)
    cerr << ", ";
  else
    cerr << "Line(" << LINE_NUM << ") ";
  stringstream ss;
  ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, LINE_NUM, T...);
}
const long long int MOD = 1e9 + 7;
const long long int MOD1 = 998244353;
const long long int N = 2e5 + 5;
const long long int INF = 1000111000111000111LL;
const long double EPS = 1e-12;
const long double PI = 3.141592653589793116;
struct Edge {
  long long int from, to, capacity;
  long double cost;
};
vector<vector<long long int>> adj, capacity;
vector<vector<long double>> cost;
void shortest_paths(long long int n, long long int v0, vector<long double> &d,
                    vector<long long int> &p) {
  d.assign(n, INF);
  d[v0] = 0.0l;
  vector<bool> inq(n, false);
  queue<long long int> q;
  q.push(v0);
  p.assign(n, -1);
  while (!q.empty()) {
    long long int u = q.front();
    q.pop();
    inq[u] = false;
    for (long long int v : adj[u]) {
      if (capacity[u][v] > 0 && d[v] > d[u] + cost[u][v]) {
        d[v] = d[u] + cost[u][v];
        p[v] = u;
        if (!inq[v]) {
          inq[v] = true;
          q.push(v);
        }
      }
    }
  }
}
long double min_cost_flow(long long int N, vector<Edge> edges, long long int K,
                          long long int s, long long int t) {
  adj.assign(N, vector<long long int>());
  cost.assign(N, vector<long double>(N, 0.0));
  capacity.assign(N, vector<long long int>(N, 0));
  for (Edge e : edges) {
    adj[e.from].push_back(e.to);
    adj[e.to].push_back(e.from);
    cost[e.from][e.to] = e.cost;
    cost[e.to][e.from] = -e.cost;
    capacity[e.from][e.to] = e.capacity;
  }
  long long int flow = 0;
  long double res = 0.0;
  vector<long long int> p;
  vector<long double> d;
  while (flow < K) {
    shortest_paths(N, s, d, p);
    if (d[t] == INF) break;
    long long int f = K - flow;
    long long int cur = t;
    while (cur != s) {
      f = min(f, capacity[p[cur]][cur]);
      cur = p[cur];
    }
    flow += f;
    res = res + f * d[t];
    cur = t;
    while (cur != s) {
      capacity[p[cur]][cur] -= f;
      capacity[cur][p[cur]] += f;
      cur = p[cur];
    }
  }
  if (flow < K)
    return -1.0l;
  else
    return res;
}
bool comp(pair<long long int, long long int> &a,
          pair<long long int, long long int> &b) {
  return a.second > b.second;
}
long double dist(pair<long long int, long long int> &a,
                 pair<long long int, long long int> &b) {
  return sqrtl(((a.first - b.first) * (a.first - b.first)) +
               ((a.second - b.second) * (a.second - b.second)));
}
int32_t main() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n;
  cin >> n;
  vector<pair<long long int, long long int>> v(n);
  for (auto &it : v) cin >> it.first >> it.second;
  sort((v).begin(), (v).end(), comp);
  vector<Edge> edges;
  for (long long int i = 0; i < n; i++) {
    Edge cur;
    cur.from = 0;
    cur.to = 2 * i + 1;
    cur.capacity = 2;
    cur.cost = 0.0l;
    edges.push_back(cur);
    for (long long int j = i + 1; j < n; j++) {
      if (v[i].second == v[j].second) continue;
      cur.from = 2 * i + 1;
      cur.to = 2 * j + 2;
      cur.capacity = 1;
      cur.cost = dist(v[i], v[j]);
      edges.push_back(cur);
    }
    cur.from = 2 * i + 2;
    cur.to = 2 * n + 1;
    cur.capacity = 1;
    cur.cost = 0.0l;
    edges.push_back(cur);
  }
  long double res = min_cost_flow(2 * n + 2, edges, n - 1, 0, 2 * n + 1);
  if (res < 0) return cout << "-1", 0;
  cout << fixed << setprecision(10) << res;
  return 0;
}

```