#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int,int> PP;

/*
    freopen("input","r",stdin);
    freopen("output","w",stdout);
*/

struct node {
    int v;
    int idx;
};

bool operator < (node a, node b) {
    if (a.v == b.v) return a.idx < b.idx;
    return a.v < b.v;
}

int L[100010], R[100010];
bool U[100010];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    for (int i = 0;i < N;i++) cin >> L[i] >> R[i];
    memset(U, 0, sizeof(U));
    ll res = 0;

    // Go left first.
    vector<node> v, u;
    for (int i = 0;i < N;i++) {
        node r;
        r.v = L[i];
        r.idx = i;
        v.push_back(r);
        r.v = R[i];
        u.push_back(r);
    }
    sort(v.begin(), v.end());
    sort(u.begin(), u.end());
    int crt = 0;
    int v_i = N - 1;
    int u_i = 0;
    int it = 0;
    bool lr = 1;
    ll ans = 0;
    while (it < N) {
        it++;
        if (lr) {
            while (U[v[v_i].idx] == 1) v_i--;
            U[v[v_i].idx] = 1;
            int id = v[v_i].idx;
            if (crt >= L[id] && crt <= R[id]) continue;
            if (crt < L[id]) {
                ans += L[id] - crt;
                crt = L[id];
            } else if (crt > R[id]) {
                ans += crt - R[id];
                crt = R[id];
            }
            v_i--;
        }
        else {
            while (U[u[u_i].idx] == 1) u_i++;
            U[u[u_i].idx] = 1;
            int id = u[u_i].idx;
            if (crt >= L[id] && crt <= R[id]) continue;
            if (crt < L[id]) {
                ans += L[id] - crt;
                crt = L[id];
            } else if (crt > R[id]) {
                ans += crt - R[id];
                crt = R[id];
            }
            u_i++;
        }
        lr = !lr;
    }
    ans += abs(crt);
    res = ans;
    crt = 0;
    v_i = N - 1;
    u_i = 0;
    it = 0;
    lr = 0;
    ans = 0;
    memset(U, 0, sizeof(U));
    while (it < N) {
        it++;
        if (lr) {
            while (U[v[v_i].idx] == 1) v_i--;
            U[v[v_i].idx] = 1;
            int id = v[v_i].idx;
            if (crt >= L[id] && crt <= R[id]) continue;
            if (crt < L[id]) {
                ans += L[id] - crt;
                crt = L[id];
            } else if (crt > R[id]) {
                ans += crt - R[id];
                crt = R[id];
            }
            v_i--;
        }
        else {
            while (U[u[u_i].idx] == 1) u_i++;
            U[u[u_i].idx] = 1;
            int id = u[u_i].idx;
            if (crt >= L[id] && crt <= R[id]) continue;
            if (crt < L[id]) {
                ans += L[id] - crt;
                crt = L[id];
            } else if (crt > R[id]) {
                ans += crt - R[id];
                crt = R[id];
            }
            u_i++;
        }
        lr = !lr;
    }
    ans += abs(crt);
    res = max(res, ans);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 2932