#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vi lnum;
typedef long double ld;

#define ALL(V) V.begin(), V.end()
#define l first
#define r second
#define SZ(V) (ll)V.size()
#define pb push_back
#define mp make_pair
#define pi 3.14159265358979
#define fopen freopen("input.txt", "r", stdin); freopen("output.txt","w", stdout)
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, b, a) for(ll i = (b) - 1; i >= (a); --i)
#define REP(i, N) FOR(i, 0, N)
#define REPR(i, N) RFOR(i, N, 0)
#define FILL(A,value) memset(A,value,sizeof(A))
#define code first
#define index second

const ll mod = 998244353;
//const ll mod = 2 * (1000 * 1000 * 1000 + 7);
const ll MOD91 = 1e9+9;
const ll MOD12 = 1e12+39LL;
const ll MOD15 = 1e15+37LL;
const ll INF = 1000 * 1000 * 1000;
const ll LINF = 1000LL*1000*1000*1000 * 1000 * 1000;
const ll base = 1e9;
const ll MAX = 2e5;
const double EPS = 1e-10;
const double EPS2 = 1e-9;
ll n;
vector<pair<ll , ll> > segment;
ll used[100000];
pair<ll , ll> getBestDist(pair<ll , ll> coords , ll curCoord)
{
	if(curCoord >= coords.l && curCoord <= coords.r)
	{
		return {0 , curCoord};
	}
	if(abs(coords.l - curCoord) < abs(coords.r - curCoord))
	{

		return {abs(coords.l - curCoord) , coords.l};
	}
	else
	{
		return {abs(coords.r - curCoord) , coords.r};
	}
}
ll brute(bool debug = 0)
{
	vector<ll> permut;
	ll ans = 0;
	for(ll i = 0; i < 8; i++)
	{
		permut.pb(i);
	}
	vector<ll> bestPermut;
	do
	{
		ll curAns = 0 , curCoord = 0;
		for(ll i = 0; i < permut.size(); i++)
		{
			pair<ll , ll> rs =  getBestDist(segment[permut[i]] , curCoord);
			curAns += rs.first;
			curCoord = rs.second;
		}
		if(curAns + abs(curCoord) > ans)
		{
			ans = curAns + abs(curCoord);
			bestPermut = permut;
		}

	}while(next_permutation(permut.begin() , permut.end()));
	if(debug)
	{
		for(int i = 0; i < bestPermut.size(); i++)
			cout << bestPermut[i] << " ";
		cout << endl;
	}
	return ans;
}

int deleted[100000];
const int offset = 100000;
vector<int> iL[200001];
vector<int> iR[200001];
vector<int> idxL[200001];
vector<int> idxR[200001];
void gen()
{
	cin >> n;
	segment.clear();
	for(ll i = 0; i < n; i++)
	{
		ll l;
		ll r;
		cin >> l >> r;



		segment.pb({l , r});
		iL[segment.back().l + offset].pb(i);
		iR[segment.back().r + offset].pb(i);
	}

}
ll solve(int param)
{
	memset(deleted , 0 , sizeof deleted);
	//cout << "P: " << param << endl;
	int L = 200000 , R = 0;
	for(int i = 0; i <= 200000; i++)
		idxL[i] = iL[i] , idxR[i] = iR[i];
	ll ans = 0 , curCoord = 0;

	for(int i = 0; i < n; i++)
	{
		if((i & 1) ^ param)
		{
			while(true)
			{

				if(!idxL[L].size())
				{
					L--;
					continue;
				}
				if(deleted[idxL[L].back()])
				{
					idxL[L].pop_back();
					continue;
				}
				break;
			}
			//cout << curCoord << " " << L - offset << endl;
			deleted[idxL[L].back()] = 1;
			if(L - offset > curCoord)
			{
				ans += abs(curCoord - (L - offset));
				curCoord = (L - offset);

			}


		}
		else
		{
			while(true)
			{
				if(!idxR[R].size())
				{
					R++;
					continue;
				}
				if(deleted[idxR[R].back()])
				{
					idxR[R].pop_back();
					continue;
				}
				break;
			}
			deleted[idxR[R].back()] = 1;
			if(R - offset < curCoord)
			{
				ans += abs(curCoord - (R - offset));
				curCoord = (R - offset);

			}
		}

	}


	return ans + abs(curCoord);
}
int main()
{
	//srand(time(NULL));

	ios_base::sync_with_stdio(0);
		gen();
		//cout << brute() << " " << solve() << endl;
	cout << max(solve(0) , solve(1));



	return 0;
}





Measured memory_bytes: 30064