func_code_string: #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;   }   