malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     int n;     cin >> n;     vector<pair<int, int>> d(n);     for (auto &i : d) cin >> i.first, i.second = &i - &d[0] + 1;     sort(d.begin(), d.end());     vector<pair<int, int>> e;     vector<int> a;     a.push_back(2 * d.back().second - 1);     for (int i = 1; i < d.back().first; ++i) a.push_back(-1);     a.push_back(2 * d.back().second);     int l = 0, r = a.size() - 1;     d.pop_back();     while (!d.empty()) {       auto p = d.back();       d.pop_back();       if (a[l + 1] == -1) {         ++l;         a[l] = 2 * p.second - 1;         if (p.first == r - l + 1) {           ++r;           a.push_back(2 * p.second);         } else {           e.push_back({l + p.first - 1, 2 * p.second});         }       } else {         ++r;         a.push_back(2 * p.second);         e.push_back({r - p.first + 1, 2 * p.second - 1});       }     }     for (size_t i = 1; i < a.size(); ++i) cout << a[i - 1] <<     << a[i] <<   n ;     for (auto &i : e) cout << a[i.first] <<     << i.second <<   n ;     return 0;   }
#include <bits/stdc++.h>   int main() {     int count, i, a, x, max, tc;     scanf( %d , &tc);     for (int j = 0; j < tc; j++) {       count = 0, max = 0;       scanf( %d , &x);       char s[x];       scanf( %s , s);       for (i = x - 1; i >= 0; i--) {         if (s[i] ==  P ) {           count += 1;         } else {           if (count > max) {             max = count;           }           count = 0;         }       }       printf( %d n , max);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 23e4 + 5;   int sum[M], n, fen[M];   int Get(int p) {     int u = p;     int ans = 0;     for (; p > 0; p -= p & -p) ans += fen[p];     for (u++; u < M; u += u & -u) fen[u]++;     return ans;   }   int get(int p) {     int cur = 0;     for (int i = 17; ~i; i--) {       int d = cur + (1 << i);       if (fen[d] <= p) p -= fen[d], cur = d;     }     int u = cur;     for (u++; u < M; u += u & -u) fen[u]--;     return cur;   }   int32_t main() {     scanf( %d , &n);     int t = 2;     while (t--) {       memset(fen, 0, sizeof fen);       for (int i = 0; i < n; i++) {         int x;         scanf( %d , &x);         sum[i] += x - Get(x);       }     }     int sb = 0;     for (int i = n - 1; ~i; i--) {       sum[i] += sb;       int k = sum[i] % (n - i);       sb = (sum[i] - k) / (n - i);       sum[i] = k;     }     for (int i = 1; i < M; i++) fen[i] = i & -i;     for (int i = 0; i < n; i++) printf( %d  , get(sum[i]));     return printf(  n ), 0;   }
#include <bits/stdc++.h>   using namespace std;   string s;   long long pos = -1;   const long long N = 5005;   long long gundy[N];   long long mex[N];   void game() {     long long len = s.length();     long long totXo = 0;     gundy[0] = 0;     for (long long i = 1; i < N; i++) {       for (long long j = 0; j < N; j++) mex[j] = 0;       for (long long j = 0; j < i; j++) {         long long l = max(0LL, j - 1);         long long r = max(0LL, i - j - 2);         long long xo = gundy[l] ^ gundy[r];         if (xo < N) mex[xo] = 1;       }       long long gv = 0;       while (gv < N && mex[gv] == 1) gv++;       gundy[i] = gv;     }     for (long long i = 1; i < len - 1; i++) {       if (s[i - 1] == s[i + 1]) {         long long j = i;         while (j + 2 < len && s[j] == s[j + 2]) j++;         totXo ^= gundy[j - i + 1];         i = j + 1;       }     }     if (totXo == 0)       cout <<  Second             <<   n ;     else {       cout <<  First             <<   n ;       for (long long i = 1; i < len - 1; i++) {         if (s[i - 1] == s[i + 1]) {           long long j = i;           while (j + 2 < len && s[j] == s[j + 2]) j++;           long long span = j - i + 1;           long long remXo = totXo ^ gundy[span];           for (long long k = 0; k < span; k++) {             long long l = max(0LL, k - 1LL);             long long r = max(0LL, span - k - 2LL);             long long xo = gundy[l] ^ gundy[r] ^ remXo;             if (xo == 0) {               pos = i + k + 1;               cout << pos <<   n ;               return;             }           }           i = j + 1;         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     cin >> s;     game();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     long long a = 0;     long long ret = 0;     long long x = n;     while (x >= 10) {       a = a * 10 + 9;       ret += 9;       x /= 10;     }     long long y = n - a;     while (y) {       ret += y % 10;       y /= 10;     }     cout << ret << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       long long int n, z = 0, o = 0;       cin >> n;       string s;       cin >> s;       if (n == 1) {         cout << s << endl;         continue;       }       for (long long int i = 0; i < n; i++) {         if (s[i] ==  0 )           z++;         else           break;       }       z++;       for (long long int i = n - 1; i >= 0; i--) {         if (s[i] ==  1 )           o++;         else           break;       }       if (o + z == n + 1) {         cout << s << endl;         continue;       }       while (z) {         cout <<  0 ;         z--;       }       while (o) {         cout <<  1 ;         o--;       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int S = 100003;   const int MOD = 1e9 + 7;   const double pi = 2 * acos(0.0);   inline int _Int() {     int x;     scanf( %d , &x);     return x;   }   inline long long _LLi() {     long long x;     scanf( %lld , &x);     return x;   }   void pruts() {     puts( NO );     exit(EXIT_SUCCESS);   }   int dirX[] = {1, 0, -1, 0, 1, -1, 1, -1};   int dirY[] = {0, 1, 0, -1, 1, -1, -1, 1};   int rX[] = {1, 1, 2, 2, -1, -1, -2, -2};   int rY[] = {2, -2, 1, -1, 2, -2, 1, -1};   template <class T>   T tri_Area(T x1, T y1, T x2, T y2, T x3, T y3) {     return abs(x1 * (y2 - y3) - y1 * (x2 - x3) + (x2 * y3 - x3 * y2));   };   template <class T>   T Distance(T x1, T y1, T x2, T y2) {     return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));   };   template <class T>   T bigMod(T n, T p, T m) {     if (p == 0) return 1;     if (p & 1) return (n * bigMod(n, p - 1, m)) % m;     T x = bigMod(n, p / 2, m);     return (x * x) % m;   };   int sset(int N, int pos) { return N = N | (1 << pos); }   bool check(int N, int pos) { return (bool)(N & (1 << pos)); }   int reset(int N, int pos) { return N = N & ~(1 << pos); }   void Hunger() {     int a = _Int();     int b = _Int();     if (!a && !b) pruts();     puts((abs(a - b) <= 1) ?  YES  :  NO );   }   int main() {     Hunger();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, k, A, B, ans = 0;   long long fmin() {     long long pros = (n - (n / k)) * A;     if (B < pros) {       n = n / k;       return B;     } else {       n = n / k;       return pros;     }   }   int main() {     cin >> n;     cin >> k;     cin >> A;     cin >> B;     if (k == 1) {       cout << (n - 1) * A;       return 0;     }     while (n != 1) {       if (n >= k) {         if (n % k == 0) {           ans += fmin();         } else {           long long t = (n % k);           n = n - t;           ans += (A * t);         }       } else {         ans = ans + (n - 1) * A;         n = 1;       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const double EPS = 1e-9;   const int INF = 1 << 29;   int main() {     int x1, y1, x2, y2;     cin >> x1 >> y1 >> x2 >> y2;     int x, y;     cin >> x >> y;     int dx = abs(x1 - x2), dy = abs(y1 - y2);     if (dx % x || dy % y) {       puts( NO );       return 0;     }     int t = dx / x - dy / y;     if (t & 1) {       puts( NO );     } else {       puts( YES );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a, s, d[100002], f, g, h, j, k, l, i, n, m;   string x;   int main() {     cin >> n;     for (i = 0; i < n; i++) {       cin >> d[i];     }     for (i = 0; i < n; i++) {       scanf(  n );       getline(cin, x);       for (a = 0; a < x.size(); a++) {         if (x[a] ==  a ) d[i]--;         if (x[a] ==  e ) d[i]--;         if (x[a] ==  i ) d[i]--;         if (x[a] ==  o ) d[i]--;         if (x[a] ==  u ) d[i]--;         if (x[a] ==  y ) d[i]--;       }       if (d[i] != 0) {         cout <<  NO ;         return 0;       }     }     cout <<  YES ;   }
#include <bits/stdc++.h>   using namespace std;   bool v[1005][1005][4][3];   char grid[1005][1005];   int dx[] = {1, -1, 0, 0};   int dy[] = {0, 0, 1, -1};   int n, m;   int xx, yy;   bool dfs(int x, int y, int dir, int turns) {     if (x < 0 || x == n || y < 0 || y == m || turns > 2 || grid[x][y] ==  * )       return false;     if (v[x][y][dir][turns]) return false;     v[x][y][dir][turns] = true;     if (x == xx && y == yy) return true;     bool can = false;     for (int i = 0; i < 4; i++)       can |= dfs(x + dx[i], y + dy[i], i, turns + (i != dir));     return can;   }   int main() {     cin >> n >> m;     pair<int, int> second, t;     for (int i = 0; i < n; i++) {       scanf( %s , grid[i]);       for (int j = 0; j < m; j++) {         if (grid[i][j] ==  S )           second = make_pair(i, j);         else if (grid[i][j] ==  T )           t = make_pair(i, j);       }     }     xx = t.first, yy = t.second;     if (dfs(second.first, second.second, 0, 0) ||         dfs(second.first, second.second, 1, 0) ||         dfs(second.first, second.second, 2, 0) ||         dfs(second.first, second.second, 3, 0))       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 300000;   vector<long long> st;   void add(vector<long long>& st, int x, long long inc) {     while (x < st.size()) {       st[x] += inc;       x |= x + 1;     }   }   long long sum(const vector<long long>& st, int x) {     long long s = 0;     while (x >= 0) {       s += st[x];       x = (x & (x + 1)) - 1;     }     return s;   }   void insert(int l, int r, long long p) {     add(st, r + 1, -p);     add(st, l, p);   }   int n, m, k;   int l[maxn], r[maxn];   long long d[maxn];   pair<int, int> a[maxn];   long long p[maxn];   int main() {     cin >> n >> m >> k;     st.resize(n + 3);     for (int i = 1; i <= n; i++) scanf( %I64d , &p[i]);     for (int i = 1; i <= m; i++) {       scanf( %d%d%I64d , &l[i], &r[i], &d[i]);     }     for (int i = 1; i <= k; i++) {       int x, y;       scanf( %d%d , &x, &y);       a[i] = make_pair(x, -1);       a[i + k] = make_pair(y + 1, 1);     }     sort(a + 1, a + 1 + 2 * k);     int sta = 1, tot = 0;     for (int i = 1; i <= m; i++) {       while (sta <= 2 * k && a[sta].first == i) tot -= a[sta++].second;       insert(l[i], r[i], d[i] * tot);     }     for (int i = 1; i <= n; i++) printf( %I64d  , sum(st, i) + p[i]);   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000 * 100 + 10;   int a[MAXN], b[MAXN];   int dp[MAXN][310];   vector<int> vec1[MAXN], vec[MAXN];   long long n, m, second, E;   bool ok(int k) {     long long need = second;     for (int i = k - 1; i < n; i++)       if (dp[i][k] < m) need = min(need, (long long)(i + 1 + dp[i][k] + 1));     need += k * E;     if (need <= second) return true;     return false;   }   int bs(int s, int e) {     if (e - s <= 1) return s;     int m = (s + e) / 2;     return ok(m) ? bs(m, e) : bs(s, m);   }   int main() {     cin >> n >> m >> second >> E;     for (int i = 0; i < n; i++) cin >> a[i], vec1[a[i]].push_back(i);     for (int i = 0; i < m; i++) cin >> b[i], vec[b[i]].push_back(i);     for (int i = 0; i < MAXN; i++) vec[i].push_back(m);     for (int i = 0; i < n; i++)       for (int j = 0; j < 301; j++) dp[i][j] = m;     for (int i = 0; i < n; i++)       for (int j = 0; j < min(min((int)m, i + 1), 300) + 1; j++) {         if (j == 0)           dp[i][j] = -1;         else if (i == 0)           dp[i][j] =               vec[a[i]][lower_bound(vec[a[i]].begin(), vec[a[i]].end(), 0) -                         vec[a[i]].begin()];         else           dp[i][j] =               min(dp[i - 1][j],                   (dp[i - 1][j - 1] >= m)                       ? (int)m                       : vec[a[i]]                            [(int)(lower_bound(vec[a[i]].begin(), vec[a[i]].end(),                                               dp[i - 1][j - 1] + 1) -                                   vec[a[i]].begin())]);       }     cout << bs(0, min({(int)m, (int)n, 300}) + 1) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000010;   int pre[N], rak[N];   int find(int first) {     if (pre[first] == -1) return first;     return pre[first] = find(pre[first]);   }   void unions(int first, int second) {     first = find(first);     second = find(second);     if (first == second) return;     if (rak[first] < rak[second]) swap(first, second);     rak[first] += rak[second];     pre[second] = first;   }   vector<pair<int, int> > rows[N], col[N];   void scc(int n, int m) {     memset(pre, -1, sizeof(pre));     fill(rak, rak + N, 1);     for (int i = 1; i <= n; i++) {       sort(rows[i].begin(), rows[i].end());       for (int j = 1; j < m; j++) {         if (rows[i][j - 1].first == rows[i][j].first)           unions((i - 1) * m + rows[i][j - 1].second,                  (i - 1) * m + rows[i][j].second);       }     }     for (int j = 1; j <= m; j++) {       sort(col[j].begin(), col[j].end());       for (int i = 1; i < n; i++) {         if (col[j][i - 1].first == col[j][i].first)           unions((col[j][i - 1].second - 1) * m + j,                  (col[j][i].second - 1) * m + j);       }     }   }   vector<int> edges[N];   int deg[N], ans[N];   stack<int> stk;   void topo(int n, int m) {     for (int i = 1; i <= n; i++) {       for (int j = 1; j < m; j++) {         if (rows[i][j - 1].first < rows[i][j].first) {           int first = find((i - 1) * m + rows[i][j - 1].second);           int second = find((i - 1) * m + rows[i][j].second);           edges[first].push_back(second);           deg[second]++;         }       }     }     for (int j = 1; j <= m; j++) {       for (int i = 1; i < n; i++) {         if (col[j][i - 1].first < col[j][i].first) {           int first = find((col[j][i - 1].second - 1) * m + j);           int second = find((col[j][i].second - 1) * m + j);           edges[first].push_back(second);           deg[second]++;         }       }     }     n = n * m;     for (int i = 1; i <= n; i++)       if (!deg[i] && pre[i] == -1) stk.push(i), ans[i] = 1;     while (!stk.empty()) {       int u = stk.top();       stk.pop();       for (int i = 0; i < edges[u].size(); i++) {         int first = edges[u][i];         ans[first] = max(ans[first], ans[u] + 1);         deg[first]--;         if (!deg[first]) stk.push(first);       }     }   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1, first; i <= n; i++) {       for (int j = 1; j <= m; j++) {         scanf( %d , &first);         rows[i].push_back(make_pair(first, j));         col[j].push_back(make_pair(first, i));       }     }     scc(n, m);     topo(n, m);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         printf( %d%c , ans[find((i - 1) * m + j)], (j == m) ?   n  :    );       }     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   using namespace std;   int t;   void solve();   struct Node {     long long q, w, e, r, t;   };   int n;   vector<Node> a;   vector<bool> ans;   int res = 0;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     t = 1;     for (int i = 0; i < t; ++i) {       solve();     }   }   void solve() {     cin >> n;     a.resize(n);     ans.resize(n);     for (int i = 0; i < int(n); ++i) {       cin >> a[i].q >> a[i].w >> a[i].e >> a[i].r >> a[i].t;     }     if (n > 66) {       cout << 0;       return;     }     for (int i = 0; i < int(n); ++i) {       for (int j = (0); j <= int(n - 1); ++j) {         for (int k = (j + 1); k <= int(n - 1); ++k) {           if (j == i || k == i) {             continue;           }           if ((a[j].q - a[i].q) * (a[k].q - a[i].q) +                   (a[j].w - a[i].w) * (a[k].w - a[i].w) +                   (a[j].e - a[i].e) * (a[k].e - a[i].e) +                   (a[j].r - a[i].r) * (a[k].r - a[i].r) +                   (a[j].t - a[i].t) * (a[k].t - a[i].t) >               0) {             ans[i] = true;             break;           }         }         if (ans[i]) break;       }       if (!ans[i]) res++;     }     cout << res << endl;     for (int i = 0; i < int(n); ++i) {       if (!ans[i]) {         cout << i + 1 << endl;       }     }   }
#include <bits/stdc++.h>   int main(void) {     int w = 1;     int h = 1;     int n = 0;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       char op[10] = {0};       scanf( %s , op);       if (strcmp(op,  UL ) == 0 || strcmp(op,  DR ) == 0)         w++;       else if (strcmp(op,  UR ) == 0 || strcmp(op,  DL ) == 0)         h++;       else {         w++;         h++;       }     }     printf( %I64d n , (long long)w * h);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, l, r;   int Niz1[100001], Niz2[100001], hes[100001], time1[100001], time2[100001];   int main() {     scanf( %d %d %d , &n, &l, &r);     for (int i = 1; i <= n; i++) {       scanf( %d , &Niz1[i]);       hes[i] = Niz1[i];     }     for (int i = 1; i <= n; i++) {       scanf( %d , &Niz2[i]);     }     for (int i = 1; i <= n; i++) {       if (i < l) {         if (hes[i] != Niz2[i]) {           printf( LIE );           return 0;         }       } else {         if (i > r) {           if (hes[i] != Niz2[i]) {             printf( LIE );             return 0;           }         } else {           time2[Niz2[i]]++;         }       }     }     for (int i = l; i <= r; i++) {       time1[Niz1[i]]++;     }     for (int i = l; i <= r; i++) {       if (time1[Niz1[i]] != time2[Niz1[i]]) {         printf( LIE );         return 0;       }     }     printf( TRUTH );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     long long cur = 1;     long long ans = 0;     long long now = n;     while (cur <= now) {       now -= cur;       cur *= 2;       ans++;     }     if (now != 0) ans++;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     int a[100009];     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> a[i];     int t = 0;     long long sum1 = 0;     sort(a, a + n);     int m = 0, l = 0, token = 0;     for (int i = n - 1; i >= 0; i--) {       if (a[i] > k) {         int temp = a[i] / k;         token = temp;         temp /= 2;         if (a[i] % k != 0) {           if (token % 2 == 1) temp++;           token++;         }         if (token % 2 == 1) {           if (l == 0)             l = 1;           else {             t++;             l = 0;           }         }         t += temp;       } else {         if (m == 0) {           m = 1;         } else {           t++;           m = 0;         }       }       if (l == 1 && m == 1 && i == 0)         t++;       else if (m == 1 && i == 0)         t++;       else if (l == 1 && i == 0)         t++;     }     cout << t <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e4 + 10;   int n, A[maxn];   int main() {     cin.sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; ++i) cin >> A[i];     int cnt = 0;     for (int i = 2; i <= n - 1; ++i)       if ((A[i] > A[i - 1] && A[i] > A[i + 1]) ||           (A[i] < A[i - 1] && A[i] < A[i + 1]))         ++cnt;     cout << cnt << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     double h, w;     cin >> h >> w;     int ans1, ans2, mx = 0;     long long int i = 1;     while (i * 2 <= h && i * 2 <= w) {       i *= 2;     }     ans1 = min((long long int)h, (long long int)(1.25 * i));     ans2 = min((long long int)w, (long long int)(1.25 * i));     if (ans1 >= ans2)       cout << ans1 <<     << i;     else       cout << i <<     << ans2;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char str[100005];     scanf( %s , str);     int l = strlen(str);     int pr = -1, i, j;     for (i =  z ; i >=  a ; i--)       for (j = 0; j < l; j++) {         if (str[j] == i && j > pr) {           cout << str[j];           pr = j;         }       }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, k;     cin >> n >> k;     long long int a[n + 1];     for (long long int i = 1; i < n; i++) cin >> a[i];     long long int i = 1;     long long int sum = 1;     while (i < n) {       if (sum >= k) break;       sum = i + a[i];       i = sum;     }     if (sum == k)       cout <<  YES  << endl;     else       cout <<  NO  << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long A, long long b) {     if (b == 0)       return A;     else       return gcd(b, A % b);   }   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   bool cmp(pair<int, int> a, pair<int, int> b) {     if (a.first != b.first) return a.first < b.first;     return a.second > b.second;   }   long long dist(pair<int, int> a, pair<int, int> b) {     return abs(a.first - b.first) + abs(a.second - b.second);   }   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     map<int, vector<pair<int, int> > > m;     for (long long i = 0; i < n; i++) {       int a, b;       cin >> a >> b;       int lvl = max(a, b);       if (m.find(lvl) == m.end()) {         vector<pair<int, int> > vec;         vec.push_back({a, b});         m[lvl] = vec;       } else {         m[lvl].push_back({a, b});       }     }     map<int, vector<pair<int, int> > >::iterator it = m.begin();     while (it != m.end()) {       sort(it->second.begin(), it->second.end(), cmp);       it++;     }     vector<vector<long long> > dp(n + 2, vector<long long>(2, 1e18));     dp[0][0] = 0;     dp[0][1] = 0;     it = m.begin();     int lvl = 1;     int pre = 0;     m[0] = {{0, 0}};     while (it != m.end()) {       pair<int, int> curl = it->second[0];       pair<int, int> curr = it->second.back();       pair<int, int> prel = m[pre][0];       pair<int, int> prer = m[pre].back();       pre = it->first;       dp[lvl][0] =           min(dp[lvl][0], dp[lvl - 1][0] + dist(prel, curr) + dist(curl, curr));       dp[lvl][0] =           min(dp[lvl][0], dp[lvl - 1][1] + dist(prer, curr) + dist(curl, curr));       dp[lvl][1] =           min(dp[lvl][1], dp[lvl - 1][0] + dist(prel, curl) + dist(curl, curr));       dp[lvl][1] =           min(dp[lvl][1], dp[lvl - 1][1] + dist(prer, curl) + dist(curl, curr));       it++;       lvl++;     }     cout << min(dp[lvl - 1][0], dp[lvl - 1][1]) << endl;     return 0;   }