#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cassert>
#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> P;

const int INF = 1e+12;
const int DEPTH = 17;

struct SegMax {
	P data[1 << (DEPTH + 1)];
	SegMax() { 
		for (int i = 0; i < (1 << (DEPTH + 1)); i++) data[i] = P(0, 0);
		for (int i = 0; i < (1 << DEPTH); i++) data[i + (1 << DEPTH) - 1] = P(0, i);
	}
	void update(int pos, int x) {
		pos += (1 << DEPTH) - 1;
		data[pos].first = x;
		while (pos > 0) {
			pos = (pos - 1) / 2;
			if (data[pos * 2 + 1].first >= data[pos * 2 + 2].first) {
				data[pos] = data[pos * 2 + 1];
			}
			else {
				data[pos] = data[pos * 2 + 2];
			}
		}
	}
	//[l, r)
	P getMax(int l, int r, int a = 0, int b = (1 << DEPTH), int id = 0) {
		if (a >= r || b <= l) return P(-INF, -1);
		if (l <= a && b <= r) return data[id];
		P u = getMax(l, r, a, a + (b - a) / 2, id * 2 + 1);
		P v = getMax(l, r, a + (b - a) / 2, b, id * 2 + 2);
		if (u.first >= v.first) return u;
		return v;
	}
};

struct SegMin {
	P data[1 << (DEPTH + 1)];
	SegMin() { 
		for (int i = 0; i < (1 << (DEPTH + 1)); i++) data[i] = P(0, 0);
		for (int i = 0; i < (1 << DEPTH); i++) data[i + (1 << DEPTH) - 1] = P(0, i);
	}
	void update(int pos, int x) {
		pos += (1 << DEPTH) - 1;
		data[pos].first = x;
		while (pos > 0) {
			pos = (pos - 1) / 2;
			if (data[pos * 2 + 1].first <= data[pos * 2 + 2].first) {
				data[pos] = data[pos * 2 + 1];
			}
			else {
				data[pos] = data[pos * 2 + 2];
			}
		}
	}
	//[l, r)
	P getMin(int l, int r, int a = 0, int b = (1 << DEPTH), int id = 0) {
		if (a >= r || b <= l) return P(INF, -1);
		if (l <= a && b <= r) return data[id];
		P u = getMin(l, r, a, a + (b - a) / 2, id * 2 + 1);
		P v = getMin(l, r, a + (b - a) / 2, b, id * 2 + 2);
		if (u.first <= v.first) return u;
		return v;
	}
};

int n;
int l[100000], r[100000];
SegMax segMax;	//左端
SegMin segMin;	//右端

signed main() {
	int i;
	
	cin >> n;
	rep(i, n) cin >> l[i] >> r[i];
	
	//左→右→左…
	rep(i, n) segMax.update(i, l[i]);
	rep(i, n) segMin.update(i, r[i]);
	
	int ans1 = 0, pos1 = 0;
	rep(i, n) {
		P res;
		int id;
		
		if (i % 2 == 0) {
			P res = segMin.getMin(0, n);
			id = res.second;
		}
		else {
			P res = segMax.getMax(0, n);
			id = res.second;
		}
		
		if (pos1 < l[id]) { ans1 += l[id] - pos1; pos1 = l[id]; }
		else if (pos1 > r[id]) { ans1 += pos1 - r[id]; pos1 = r[id]; }
		
		segMin.update(id, INF);
		segMax.update(id, -INF);
	}
	ans1 += abs(pos1);
	
	//右→左→右…
	rep(i, n) segMax.update(i, l[i]);
	rep(i, n) segMin.update(i, r[i]);
	
	int ans2 = 0, pos2 = 0;
	rep(i, n) {
		P res;
		int id;
		
		if (i % 2 == 1) {
			P res = segMin.getMin(0, n);
			id = res.second;
		}
		else {
			P res = segMax.getMax(0, n);
			id = res.second;
		}
		
		if (pos2 < l[id]) { ans2 += l[id] - pos2; pos2 = l[id]; }
		else if (pos2 > r[id]) { ans2 += pos2 - r[id]; pos2 = r[id]; }
		
		segMin.update(id, INF);
		segMax.update(id, -INF);
	}
	ans2 += abs(pos2);
	
	//答え
	cout << max(ans1, ans2) << endl;
	return 0;
}

Measured memory_bytes: 10112