malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   struct sur {     int c1, c2, c3, c4;     inline bool colsame() { return c1 == c3 && c2 == c4 && c1 != c2; }     inline bool same() { return c1 == c2 && c2 == c3 && c3 == c4; }     inline void right_rotate() {       int t = c4;       c4 = c2;       c2 = c1;       c1 = c3;       c3 = t;       return;     }     inline void left_rotate() {       int t = c4;       c4 = c3;       c3 = c1;       c1 = c2;       c2 = t;       return;     }     inline void rotate() {       int t = c1;       c1 = c4;       c4 = t;       t = c2;       c2 = c3;       c3 = t;       return;     }     inline void read() {       scanf( %d%d%d%d , &c1, &c2, &c3, &c4);       return;     }     friend inline bool round(sur s1, sur s2, sur s3, sur s4) {       if (!(s1.colsame() && s2.colsame() && s3.colsame() && s4.colsame()))         return 0;       if (s1.c1 == s2.c2 && s2.c1 == s3.c2 && s3.c1 == s4.c2 && s4.c1 == s1.c2)         return 1;       if (s1.c2 == s2.c1 && s2.c2 == s3.c1 && s3.c2 == s4.c1 && s4.c2 == s1.c1)         return 1;       return 0;     }   } code[7];   template <class Tp>   inline void swap(Tp &a, Tp &b) {     Tp t = a;     a = b;     b = t;     return;   }   int main() {     int i;     for (i = 1; i <= 6; i++) code[i].read();     if (code[4].same() && code[5].same()) {       code[6].rotate();       puts(round(code[1], code[2], code[3], code[6]) ?  YES  :  NO );     } else if (code[1].same() && code[3].same()) {       code[4].right_rotate();       code[2].right_rotate();       code[5].right_rotate();       code[6].right_rotate();       puts(round(code[4], code[2], code[5], code[6]) ?  YES  :  NO );     } else if (code[2].same() && code[6].same()) {       code[1].right_rotate();       code[3].left_rotate();       code[4].rotate();       puts(round(code[4], code[1], code[5], code[3]) ?  YES  :  NO );     } else       puts( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   int dp[17][1 << 16][2][2];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     for (int i = 0; i < 17; i++) {       for (int j = 0; j < (1 << 16); j++) {         for (int k = 0; k < 2; k++) {           for (int l = 0; l < 2; l++) {             dp[i][j][k][l] = -inf;           }         }       }     }     int n, k;     cin >> n >> k;     vector<int> good(1 << n);     while (k--) {       int x;       cin >> x;       x--;       good[x] = true;     }     for (int i = 0; i < (1 << n); i += 2) {       dp[0][i / 2][good[i]][good[i + 1]] =           max(dp[0][i / 2][good[i]][good[i + 1]], good[i] | good[i + 1]);       dp[0][i / 2][good[i + 1]][good[i]] =           max(dp[0][i / 2][good[i + 1]][good[i]], good[i] | good[i + 1]);     }     for (int l = 0; l + 1 < n; l++) {       int p = (1 << n) / (1 << (l + 1));       for (int i = 0; i < p; i += 2) {         for (int u1 = 0; u1 < 2; u1++) {           for (int d1 = 0; d1 < 2; d1++) {             for (int u2 = 0; u2 < 2; u2++) {               for (int d2 = 0; d2 < 2; d2++) {                 int d = (d1 | d2);                 if (d) {                   int u = u1 | u2;                   int m = 2 + u;                   dp[l + 1][i / 2][u][d] =                       max(dp[l + 1][i / 2][u][d],                           dp[l][i][u1][d1] + dp[l][i + 1][u2][d2] + m);                 } else {                   if (u1 & u2) {                     dp[l + 1][i / 2][1][1] =                         max(dp[l + 1][i / 2][1][1],                             dp[l][i][u1][d1] + dp[l][i + 1][u2][d2] + 2);                   } else if (u1 | u2) {                     dp[l + 1][i / 2][1][0] =                         max(dp[l + 1][i / 2][1][0],                             dp[l][i][u1][d1] + dp[l][i + 1][u2][d2] + 1);                     dp[l + 1][i / 2][0][1] =                         max(dp[l + 1][i / 2][0][1],                             dp[l][i][u1][d1] + dp[l][i + 1][u2][d2] + 2);                   } else {                     dp[l + 1][i / 2][0][0] =                         max(dp[l + 1][i / 2][0][0],                             dp[l][i][u1][d1] + dp[l][i + 1][u2][d2]);                   }                 }               }             }           }         }       }     }     int ans = 0;     for (int u = 0; u < 2; u++) {       for (int d = 0; d < 2; d++) {         ans = max(ans, dp[n - 1][0][u][d] + (u | d));       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Team {     string name;     int fi, se, th;   } t[60];   int cmp(Team a, Team b) {     if (a.fi != b.fi)       return a.fi > b.fi;     else if (a.se != b.se)       return a.se > b.se;     else       return a.th > b.th;   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> t[i].name;       t[i].fi = t[i].se = t[i].th = 0;     }     for (int i = 0; i < n * (n - 1) / 2; i++) {       string te, t1, t2;       int a, b;       char ch;       cin >> te >> a >> ch >> b;       t1 = te.substr(0, te.find( - ));       t2 = te.substr(te.find( - ) + 1);       for (int j = 0; j < n; j++) {         if (t[j].name == t1) {           if (a > b)             t[j].fi += 3;           else if (a == b)             t[j].fi += 1;           t[j].se += a - b;           t[j].th += a;         }         if (t[j].name == t2) {           if (a < b)             t[j].fi += 3;           else if (a == b)             t[j].fi += 1;           t[j].se += b - a;           t[j].th += b;         }       }     }     string ans[30];     sort(t, t + n, cmp);     for (int i = 0; i < n / 2; i++) ans[i] = t[i].name;     sort(ans, ans + n / 2);     for (int i = 0; i < n / 2; i++) cout << ans[i] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-6;   const double pi = 3.14159265358979323846264338;   inline long long multi(long long x, long long y) {     long long tmp =         (x * y -          (long long)((long double)x / 998244353 * y + 1.0e-8) * 998244353);     return tmp < 0 ? tmp + 998244353 : tmp;   }   long long _ceil(long long a, long long b);   long long _floor(long long a, long long b) {     return b < 0 ? _floor(-a, -b) : a < 0 ? -_ceil(-a, b) : a / b;   }   long long _ceil(long long a, long long b) {     return b < 0 ? _ceil(-a, -b) : a < 0 ? -_floor(-a, b) : (a + b - 1) / b;   }   long long exgcd(long long a, long long b, long long &x, long long &y) {     if (b == 0) {       x = 1;       y = 0;       return a;     }     long long d = exgcd(b, a % b, y, x);     y -= x * (a / b);     return d;   }   int32_t main() {     ios ::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long a1, a2, b1, b2, x0, y0;     long long l, r;     cin >> a1 >> b1 >> a2 >> b2 >> l >> r;     l = max(0ll, _ceil(l - b1, a1));     r = _floor(r - b1, a1);     if (l > r) {       cout << 0 <<   n ;       return 0;     }     long long g = exgcd(a1, -1 * a2, x0, y0);     long long m = b2 - b1;     if (m % g) {       cout << 0 <<   n ;       return 0;     }     if (g < 0) {       g *= -1;       x0 *= -1;       y0 *= -1;     }     long long L = _ceil(r * g - x0 * m, -a2);     long long R = _floor(l * g - x0 * m, -a2);     R = min(R, _floor(y0 * m, a1));     long long ans = max(0ll, R - L + 1);     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct yts {     long long dp[210][210];   } a, ans, t;   int ch[210][26], fail[210], q[210], root = 1;   long long w[210], b[210];   int n, m, tot = 1;   char s[210];   long long L;   void insert(int id) {     int x = root, len = strlen(s + 1);     for (int i = 1; i <= len; i++) {       int t = s[i] -  a ;       if (!ch[x][t]) ch[x][t] = ++tot;       x = ch[x][t];     }     w[x] += b[id];   }   void build_fail() {     int l = 0, r = 0;     for (int i = 0; i < 26; i++)       if (ch[root][i])         fail[ch[root][i]] = root, q[++r] = ch[root][i];       else         ch[root][i] = root;     while (l < r) {       int x = q[++l];       w[x] += w[fail[x]];       for (int i = 0; i < 26; i++)         if (ch[x][i])           fail[ch[x][i]] = ch[fail[x]][i], q[++r] = ch[x][i];         else           ch[x][i] = ch[fail[x]][i];     }   }   void mul(yts &c, yts &a, yts &b) {     memset(t.dp, -1, sizeof(t.dp));     for (int k = 1; k <= tot; k++)       for (int i = 1; i <= tot; i++)         for (int j = 1; j <= tot; j++)           if (a.dp[i][k] != -1 && b.dp[k][j] != -1)             t.dp[i][j] = max(t.dp[i][j], a.dp[i][k] + b.dp[k][j]);     for (int i = 1; i <= tot; i++)       for (int j = 1; j <= tot; j++) c.dp[i][j] = t.dp[i][j];   }   void power() {     memset(ans.dp, -1, sizeof(ans.dp));     for (int i = 1; i <= tot; i++) ans.dp[i][i] = 0;     while (L) {       if (L & 1) mul(ans, ans, a);       mul(a, a, a);       L >>= 1;     }   }   void build_a() {     memset(a.dp, -1, sizeof(a.dp));     for (int i = 1; i <= tot; i++)       for (int c = 0; c < 26; c++) {         if (a.dp[i][ch[i][c]] == -1) a.dp[i][ch[i][c]] = 0;         a.dp[i][ch[i][c]] += w[ch[i][c]];       }   }   int main() {     scanf( %d%I64d , &n, &L);     for (int i = 1; i <= n; i++) scanf( %I64d , &b[i]);     for (int i = 1; i <= n; i++) {       scanf( %s , s + 1);       insert(i);     }     build_fail();     build_a();     power();     long long ANS = 0;     for (int i = 1; i <= tot; i++)       if (ans.dp[root][i] != -1) ANS = max(ANS, ans.dp[root][i]);     printf( %I64d n , ANS);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize(2)   #pragma GCC optimize(3)   using namespace std;   template <typename T1, typename T2>   void ckmin(T1 &a, T2 b) {     if (a > b) a = b;   }   template <typename T1, typename T2>   void ckmax(T1 &a, T2 b) {     if (a < b) a = b;   }   template <typename T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   int read() {     int x = 0, f = 0;     char ch = getchar();     while (!isdigit(ch)) f |= ch ==  - , ch = getchar();     while (isdigit(ch)) x = 10 * x + ch -  0 , ch = getchar();     return f ? -x : x;   }   const int N = 200005;   long long a[N], b[N], sum;   int n, k;   int main() {     n = read(), k = read();     for (register int i = 1; i <= k; i++)       a[i] = read(), b[i] = read(), sum += b[i];     if (sum > n) puts( -1 ), exit(0);     if (sum < n) puts( 1 ), exit(0);     long long res = 0;     for (register int i = 1; i <= k; i++) res = (res + a[i] * b[i]) % n;     res = (res - 1ll * n * (n + 1) / 2) % n;     if (res == 0)       puts( 1 );     else       puts( -1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct problem {     int score1, score2;     int time1, time2;     double fail;     long long expscore1, expscore2;     double ratio;   };   int N, T;   problem P[1010];   long long dpscore[1010][1600];   double dppenal[1010][1600];   void update(int n, int t, long long score, double penal) {     if (n <= N && t <= T &&         (score > dpscore[n][t] ||          (score == dpscore[n][t] && penal < dppenal[n][t]))) {       dpscore[n][t] = score;       dppenal[n][t] = penal;     }   }   int main(void) {     int i, j;     cin >> N >> T;     for ((i) = 0; (i) < (int)(N); (i)++) {       cin >> P[i].score1 >> P[i].score2 >> P[i].time1 >> P[i].time2 >> P[i].fail;       P[i].expscore1 = (long long)P[i].score1 * (long long)1000000;       int tmp = (int)(P[i].fail * 1000000 + 0.5);       P[i].expscore2 = (long long)P[i].score2 * (long long)(1000000 - tmp);       P[i].ratio =           ((tmp == 1000000) ? (1.0E+18)                             : (P[i].time2 * P[i].fail / (1.0 - P[i].fail)));     }     for ((i) = 0; (i) < (int)(N + 5); (i)++)       for ((j) = 0; (j) < (int)(N - 1); (j)++)         if (P[j].ratio > P[j + 1].ratio) swap(P[j], P[j + 1]);     for ((i) = 0; (i) < (int)(N + 1); (i)++)       for ((j) = 0; (j) < (int)(T + 1); (j)++) dpscore[i][j] = -1;     dpscore[0][0] = 0;     for ((i) = 0; (i) < (int)(N); (i)++)       for ((j) = 0; (j) < (int)(T + 1); (j)++)         if (dpscore[i][j] != -1) {           long long score = dpscore[i][j];           double penal = dppenal[i][j];           update(i + 1, j, score, penal);           update(i + 1, j + P[i].time1, score + P[i].expscore1,                  penal + P[i].time1);           double fail_penalty = penal + P[i].time1;           double ac_penalty = j + P[i].time1 + P[i].time2;           update(i + 1, j + P[i].time1 + P[i].time2,                  score + P[i].expscore1 + P[i].expscore2,                  fail_penalty * P[i].fail + ac_penalty * (1.0 - P[i].fail));         }     long long score = 0;     double penal = 0.0;     for ((i) = 0; (i) < (int)(T + 1); (i)++) {       long long score2 = dpscore[N][i];       double penal2 = dppenal[N][i];       if (score2 > score || (score2 == score && penal2 < penal)) {         score = score2;         penal = penal2;       }     }     printf( %.12f %.12f n , score / 1000000.0, penal);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   T sqr(T x) {     return x * x;   }   template <typename T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   const int MAXN = 600;   int n, m;   int x, y, cnt;   bool us[MAXN][MAXN];   string s;   int main() {     ios_base ::sync_with_stdio(false);     cin >> n >> m >> x >> y;     cin >> s;     for (int i = 0; i < s.size(); i++) {       if (us[x][y])         cout <<  0  ;       else         cout <<  1  ;       us[x][y] = true;       if (s[i] ==  U ) x--;       if (s[i] ==  D ) x++;       if (s[i] ==  L ) y--;       if (s[i] ==  R ) y++;       if (x > n) x = n;       if (x == 0) x = 1;       if (y > m) y = m;       if (y == 0) y = 1;     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (!us[i][j]) cnt++;     cout << cnt;   }
#include <bits/stdc++.h>   int a[100010];   int main() {     int n;     int b = 0, c = 0, d = 0, td = 0, ex1 = 0, ex2 = 0, ex;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       if (a[i] == 1)         b++;       else if (a[i] == 2)         c++;       else if (a[i] == 3)         d++;       else if (a[i] == 4)         td++;     }     td += d;     if (c % 2 == 0) {       td += (c / 2);     } else {       ex2 = (c % 2);       td += (c / 2);     }     if (b > d) {       ex1 = b - d;     }     ex = (2 * ex2) + ex1;     if (ex % 4 == 0)       td += (ex / 4);     else       td += (ex / 4) + 1;     printf( %d , td);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string arr[n], mx =  2011 ;     for (int i = 0; i < n; i++) cin >> arr[i];     for (int p = n - 1; p >= 0; p--) {       string maxi =  0000 ;       for (int i = 0; i <= 3; i++) {         char s = arr[p][i];         for (int j = 9; j >= 0; j--) {           arr[p][i] = char( 0  + j);           if (arr[p] <= mx && arr[p] >=  1000 ) {             if (arr[p] > maxi) maxi = arr[p];           }         }         arr[p][i] = s;       }       if (maxi ==  0000 ) {         cout <<  No solution  << endl;         return 0;       }       arr[p] = maxi;       mx = maxi;     }     for (int i = 0; i < n; i++) {       cout << arr[i] << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int num = 0;     char ch = getchar();     while (!isdigit(ch)) ch = getchar();     while (isdigit(ch)) num *= 10, num += ch - 48, ch = getchar();     return num;   }   int x, y;   int main() {     int n = read();     for (int i = 1; i <= n; i++) x |= read();     for (int i = 1; i <= n; i++) y |= read();     printf( %d n , x + y);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct solution {     int t, n{0};     vector<int> a{};     void get_data() { cin >> t; }     void solve() {       while (t--) {         cin >> n;         a.clear();         a.resize(n);         for (auto &el : a) cin >> el;         auto f = a[0];         auto s = a[1];         bool printed = false;         for (auto i = 2; i < a.size(); ++i) {           if ((f + s) <= a[i]) {             cout << 1 <<     << 2 <<     << i + 1 <<   n ;             printed = true;             break;           }         }         if (!printed) cout <<  -1 n ;       }     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     solution s;     s.get_data();     s.solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, mp[505][505], del[505], vis[505], ans[505];   signed main() {     cin >> n;     for (long long i = 1; i <= n; i++)       for (long long j = 1; j <= n; j++) scanf( %lld , &mp[i][j]);     for (long long i = 1; i <= n; i++) scanf( %lld , &del[i]);     for (long long tim = n; tim >= 1; tim--) {       long long now = del[tim];       vis[now] = 1;       for (long long i = 1; i <= n; i++)         for (long long j = 1; j <= n; j++) {           mp[i][j] = min(mp[i][j], mp[i][now] + mp[now][j]);           if (vis[i] && vis[j]) ans[tim] += mp[i][j];         }     }     for (long long i = 1; i <= n; i++) cout << ans[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     ll t;     cin >> t;     while (t--) {       ll n;       cin >> n;       vector<ll> a(n);       for (ll i = 0; i < n; i++) {         cin >> a[i];       }       bool strictly_decreasing = true;       for (ll i = 1; i < n; i++) {         if (a[i] >= a[i - 1]) {           strictly_decreasing = false;           break;         }       }       if (strictly_decreasing) {         cout <<  NO  << endl;       } else {         cout <<  YES  << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 100000;   const long long inf = (long long)1e9;   const long long MOD = (long long)1e9 + 7;   const long double eps = 1e-6;   const long long ABC = 26;   const long long P = 239;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.precision(20);     long long n;     cin >> n;     long long cnt = 0;     for (long long i = 1; i <= 2000000; i++) {       long long x = n + i;       if (x % 3 != 0)         continue;       else         x /= 3;       if (i * (i + 1) / 2 <= x) cnt++;     }     cout << cnt << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 10;   const int MOD = 1e9 + 7;   int n, l, m;   struct Matrix {     int mat[105][105];     void init() { memset(mat, 0, sizeof mat); }   };   Matrix operator*(Matrix A, Matrix B) {     Matrix C;     C.init();     for (int i = 0; i < m; i++) {       for (int j = 0; j < m; j++) {         for (int k = 0; k < m; k++) {           C.mat[i][j] =               (C.mat[i][j] + 1LL * A.mat[i][k] * B.mat[k][j] % MOD) % MOD;         }       }     }     return C;   }   Matrix operator^(Matrix A, int k) {     Matrix B;     B.init();     for (int i = 0; i < m; i++) B.mat[i][i] = 1;     while (k) {       if (k & 1) B = B * A;       A = A * A;       k >>= 1;     }     return B;   }   int a[105];   int b[MAXN];   template <class T>   inline void scan_d(T &ret) {     char c;     ret = 0;     while ((c = getchar()) <  0  || c >  9 )       ;     while (c >=  0  && c <=  9 ) ret = ret * 10 + (c -  0 ), c = getchar();   }   int main() {     Matrix B;     B.init();     scanf( %d%d%d , &n, &l, &m);     for (int i = 0; i < n; i++) {       int x;       scan_d(x);       int d = x % m;       B.mat[0][d]++;     }     for (int i = 0; i < n; i++) {       int x;       scan_d(x);       a[x % m]++;       b[i] = x % m;     }     Matrix A;     A.init();     for (int i = 0; i < m; i++) {       int zz = i;       for (int j = 0; j <= i; j++) {         A.mat[j][i] = a[zz--];       }       zz = m - 1;       for (int j = i + 1; j < m; j++) {         A.mat[j][i] = a[zz--];       }     }     A = A ^ (l - 2);     A = B * A;     B.init();     for (int i = 0; i < n; i++) {       int x;       scan_d(x);       (b[i] += x) %= m;       int d = b[i];       if (d) d = m - d;       B.mat[d][0]++;     }     A = A * B;     cout << A.mat[0][0] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<int, int> mp;   int Find(int x) {     if (mp.find(x) == mp.end()) return x;     return mp[x] = Find(mp[x]);   }   int main() {     int n;     while (scanf( %d , &n) != EOF) {       mp.clear();       int a;       for (int i = 0; i < n; i++) {         scanf( %d , &a);         a = Find(a);         mp[a] = a + 1;         if (i) printf(   );         printf( %d , a);       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = (long long)1e2;   const int INF = (long long)1e9;   const int MOD = (long long)1e9 + 7;   const int CHR = 97;   double MINcpk;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m;     double a, b;     cin >> n >> m;     MINcpk = INF;     for (int i = 0; i < n; i++) cin >> a >> b, MINcpk = min(a / b, MINcpk);     cout << fixed << setprecision(9) << MINcpk * m;     return cout <<   n , 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[27] = {0};   int main() {     int i, j, m, n, t;     string s;     cin >> n;     cin >> s;     for (i = 0; i < n; i++) a[s[i] -  a  + 1]++;     for (i = 1; i <= 26; i++)       if (a[i] == n) {         cout <<  NO  << endl;         return 0;       }     for (i = 0; i < n - 1; i++) {       if (s[i] != s[i + 1]) {         cout <<  YES  << endl;         cout << s[i] << s[i + 1] << endl;         return 0;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long dp[2][55];   long long m[55];   long long n;   int main() {     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> m[i];     }     for (long long i = n - 1; i >= 0; i--) {       dp[0][i] = max(dp[1][i + 1] + m[i], dp[0][i + 1]);       dp[1][i] = min(dp[1][i + 1] + m[i], dp[0][i + 1]);     }     cout << dp[1][0] <<     << dp[0][0];   }
#include <bits/stdc++.h>   const int inf = 1e9;   using namespace std;   struct data {     int obj, pre, c;     double w;   } e[200500 * 2];   int head[200500], cur[200500], uu[200500], c[200500];   double dis[200500];   int n, tot = 1, s, t;   double ans = 0;   struct node {     double x, y;   } a[200500];   void insert(int x, int y, int c, double w) {     e[++tot].obj = y;     e[tot].pre = head[x];     e[tot].c = c;     e[tot].w = w;     head[x] = tot;     e[++tot].obj = x;     e[tot].pre = head[y];     e[tot].c = 0;     e[tot].w = -w;     head[y] = tot;   }   bool spfa() {     for (int i = 0; i <= t; i++) uu[i] = 0;     for (int i = 0; i <= t; i++) dis[i] = 1.0 * inf;     dis[0] = 0;     queue<int> q;     q.push(0);     while (!q.empty()) {       int u = q.front();       q.pop();       uu[u] = 1;       for (int j = head[u]; j; j = e[j].pre) {         int v = e[j].obj;         if (e[j].c > 0 && dis[v] > dis[u] + e[j].w + 1e-9) {           dis[v] = dis[u] + e[j].w;           if (uu[v] == 0) uu[v] = 1, q.push(v);         }       }       uu[u] = 0;     }     if (dis[t] >= 1.0 * inf) return 0;     return 1;   }   int dfs(int x, int mx) {     if (x == t || mx == 0) return mx;     uu[x] = 1;     int used = 0;     for (int j = cur[x]; j; j = e[j].pre) {       int v = e[j].obj;       if (fabs(dis[v] - (dis[x] + e[j].w)) < 1e-9 && e[j].c > 0 && uu[v] == 0) {         int w = dfs(v, min(e[j].c, mx - used));         ans += 1.0 * w * e[j].w;         e[j].c -= w;         e[j ^ 1].c += w;         used += w;         cur[x] = j;         if (used == mx) return used;       }     }     return used;   }   double sqr(double x) { return x * x; }   double D(node a, node b) { return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y)); }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %lf%lf , &a[i].x, &a[i].y);     s = 0;     t = 2 * n + 1;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         if (a[i].y > a[j].y) insert(i, j + n, 1, D(a[i], a[j]));     for (int i = 1; i <= n; i++) insert(s, i, 2, 0);     for (int i = 1; i <= n; i++) insert(i + n, t, 1, 0);     int flow = 0;     while (spfa()) {       for (int i = 0; i <= t; i++) cur[i] = head[i], uu[i] = 0;       flow += dfs(s, inf);     }     if (flow != n - 1)       puts( -1 );     else       printf( %.10lf n , ans);     return 0;   }