#include "bits/stdc++.h"

using namespace std;

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i,n) for(ll i=1;i<=(ll)(n);i++)
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(ll)(n);i>0;i--)
#define REP(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
const ll inf = 1000000001;
const ll INF = 2e18;
const ll MOD = 1000000007;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);




bool cmp1(pair<pii, int> a, pair<pii, int> b) {
	if (a.first.first != b.first.first) {
		return a.first.first > b.first.first;
	}
	else if (a.first.second != b.first.second) {
		return a.first.second > b.first.second;
	}
	else {
		return a.second < b.second;
	}
}

bool cmp2(pair<pii, int> a, pair<pii, int> b) {
	if (a.first.second != b.first.second) {
		return a.first.second < b.first.second;
	}
	else if (a.first.first != b.first.first) {
		return a.first.first < b.first.first;
	}
	else {
		return a.second < b.second;
	}
}

int main() {
	int n;
	cin >> n;
	vector<pair<pii, int> > lr(n);
	rep(i, n) {
		cin >> lr[i].first.first >> lr[i].first.second;
		lr[i].second = i;
	}
	auto lr2 = lr;
	vi l(n);
	sort(all(lr2), cmp1);
	rep(i, n) {
		l[i] = lr2[i].second;
	}
	vi r(n);
	sort(all(lr2), cmp2);
	rep(i, n) {
		r[i] = lr2[i].second;
	}
	ll ans = 0;
	//DEBUG_VEC(l); DEBUG_VEC(r);
	rep(saisyo, 2) {
		int il = 0, ir = 0;
		ll now = 0;
		ll sum = 0;
		bool flag = saisyo;
		//DEBUG(flag);
		vector<bool> used(n, false);
		rep(i, n) {
			//DEBUG(sum); DEBUG(now);
			if (flag) {
				while (used[r[ir]]) {
					ir++;
				}
				int idx = r[ir];
				used[idx] = true;
				if (in(now, lr[idx].first.first, lr[idx].first.second + 1)) {
					sum += 0;
				}
				else if (now < lr[idx].first.first) {
					sum += lr[idx].first.first - now;
					now = lr[idx].first.first;
				}
				else {
					sum += now - lr[idx].first.second;
					now = lr[idx].first.second;
				}
			}
			else {
				while (used[l[il]]) {
					il++;
				}
				int idx = l[il];
				used[idx] = true;
				if (in(now, lr[idx].first.first, lr[idx].first.second + 1)) {
					sum += 0;
				}
				else if (now < lr[idx].first.first) {
					sum += lr[idx].first.first - now;
					now = lr[idx].first.first;
				}
				else {
					sum += now - lr[idx].first.second;
					now = lr[idx].first.second;
				}
			}
			flag = !flag;
		}
		//DEBUG(sum); DEBUG(now);
		sum += abs(now);
		chmax(ans, sum);
	}
	cout << ans << endl;

}

Measured memory_bytes: 3328