#include "bits/stdc++.h"
using namespace std;
const int maxn = 100100;
long long cat(vector<pair<int, int> > s, int dir){
    multiset<pair<int, int> > p0, p1;
    for(auto e : s) p0.insert(e);
    for(auto e : s) p1.insert(make_pair(e.second, e.first));
    long long res = 0;
    pair<int,int> now(0,0);
    for(int e = 0; e < s.size(); e++){
        // for(auto e : p0) cerr << "(" << e.first << " " << e.second << ") "; cerr << endl;
        // for(auto e : p1) cerr << "(" << e.first << " " << e.second << ") "; cerr << endl;
        bool done = false;
        if(dir == 0){
            auto it = *--p0.end();
            if(it.first >= now.first){
                res += it.first - now.first;
                // cerr << "1 from " << now.first << " to " << it.first << endl;
                now = {it.first, it.first};
                done = true;
                p0.erase(p0.find(it));
                p1.erase(p1.find(make_pair(it.second, it.first)));
            }
        } else {
            auto it = *p1.begin();
            if(it.first <= now.first){
                // cerr << "1 from " << now.first << " to " << it.first << endl;
                res += now.first - it.first;
                now = {it.first, it.first};
                done = true;
                p0.erase(p0.find(make_pair(it.second, it.first)));
                p1.erase(p1.find(it));
            }
        }
        dir ^= 1;
        if(!done){
            if(dir == 0){
                auto it = *--p0.end();
                if(it.first >= now.first){
                    // cerr << "2 from " << now.first << " to " << it.first << endl;
                    res += it.first - now.first;
                    now = {it.first, it.first};
                    done = true;
                    p0.erase(p0.find(it));
                    p1.erase(p1.find(make_pair(it.second, it.first)));
                }
            } else {
                auto it = *p1.begin();
                if(it.first <= now.first){
                    // cerr << "2 from " << now.first << " to " << it.first << endl;
                    res += now.first - it.first;
                    now = {it.first, it.first};
                    done = true;
                    p0.erase(p0.find(make_pair(it.second, it.first)));
                    p1.erase(p1.find(it));
                }
            }
            dir ^= 1;
        }
        if(!done){
            if(dir == 0){
                auto it = *--p0.end();
                done = true;
                p0.erase(p0.find(it));
                p1.erase(p1.find(make_pair(it.second, it.first)));
            } else {
                auto it = *p1.begin();

                done = true;
                p0.erase(p0.find(make_pair(it.second, it.first)));
                p1.erase(p1.find(it));
            }
            dir ^= 1;
        }
    }
    // cerr << "from " << now.first << " to " << 0 << endl;
    res += abs(now.first);
    // cerr << "cost " << res << endl;
    return res;
}
int MAIN(){
    int n;
    if(!(cin >> n)) return 0;
    vector<pair<int, int> > s(n);
    for(auto & e : s) cin >> e.first >> e.second;
    long long r = 0;
    r = max(r, cat(s, 0));
    r = max(r, cat(s, 1));
    cout << r << endl;
    return 1;
}
int main(){
    // init();
    while(MAIN());
    return 0;
}


Measured memory_bytes: 11136