import std.stdio;
import std.range;
import std.array;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.container;
import std.typecons;
import std.random;
import std.csv;
import std.regex;
import std.math;
import core.time;
import std.ascii;
import std.digest.sha;
import std.outbuffer;
import std.numeric;
import std.bigint;
import core.checkedint;
import core.bitop;

alias Node = Tuple!(int, "l", int, "r");
long solve1(Node[] nodes, int index, int base)
{
	if (nodes[index].l <= 0 && 0 <= nodes[index].r) {
		base = 0;
	} else if (nodes[index].l.abs <= nodes[index].r.abs) {
		base = nodes[index].l;
	} else {
		base = nodes[index].r;
	}
	alias LeftTree = RedBlackTree!(Node, (a, b) => a.r < b.r, true);
	alias RightTree = RedBlackTree!(Node, (a, b) => a.l < b.l, true);
	LeftTree lefts = new LeftTree();
	RightTree rights = new RightTree();
	foreach (node; nodes) {
		if (node.l <= base && base <= node.r) {
			continue;
		}
		if (node.r < base) {
			lefts.insert(node);
		}
		if (base < node.l) {
			rights.insert(node);
		}
	}
	long ans = base.abs;
	int ite = base;
	while (lefts.length && rights.length) {
		Node left = lefts.back;
		Node right = rights.front;
		lefts.removeBack;
		rights.removeFront;
		if (abs(left.r - ite) <= abs(left.l - ite)) {
			ans += abs(ite - left.r);
			ite = left.r;
		} else {
			ans += abs(ite - left.l);
			ite = left.l;
		}
		if (abs(right.r - ite) <= abs(right.l - ite)) {
			ans += abs(ite - right.r);
			ite = right.r;
		} else {
			ans += abs(ite - right.l);
			ite = right.l;
		}
	}
	if (lefts.length) {
		Node left = lefts.front;
		ans += abs(ite - left.r);
		ite = left.r;
	}
	if (rights.length) {
		Node right = rights.back;
		ans += abs(ite - right.l);
		ite = right.l;
	}
	ans += ite.abs;
	return ans;
}
long solve2(Node[] nodes, int index, int base)
{
	if (nodes[index].l <= 0 && 0 <= nodes[index].r) {
		base = 0;
	} else if (nodes[index].l.abs <= nodes[index].r.abs) {
		base = nodes[index].l;
	} else {
		base = nodes[index].r;
	}
	alias LeftTree = RedBlackTree!(Node, (a, b) => a.r < b.r, true);
	alias RightTree = RedBlackTree!(Node, (a, b) => a.l < b.l, true);
	LeftTree lefts = new LeftTree();
	RightTree rights = new RightTree();
	foreach (node; nodes) {
		if (node.l <= base && base <= node.r) {
			continue;
		}
		if (node.r < base) {
			lefts.insert(node);
		}
		if (base < node.l) {
			rights.insert(node);
		}
	}
	long ans = base.abs;
	int ite = base;
	while (lefts.length && rights.length) {
		Node left = lefts.back;
		Node right = rights.front;
		lefts.removeBack;
		rights.removeFront;
		if (abs(right.r - ite) <= abs(right.l - ite)) {
			ans += abs(ite - right.r);
			ite = right.r;
		} else {
			ans += abs(ite - right.l);
			ite = right.l;
		}
		if (abs(left.r - ite) <= abs(left.l - ite)) {
			ans += abs(ite - left.r);
			ite = left.r;
		} else {
			ans += abs(ite - left.l);
			ite = left.l;
		}
	}
	if (lefts.length) {
		Node left = lefts.front;
		ans += abs(ite - left.r);
		ite = left.r;
	}
	if (rights.length) {
		Node right = rights.back;
		ans += abs(ite - right.l);
		ite = right.l;
	}
	ans += ite.abs;
	return ans;
}

void main()
{
	int n = readln.chomp.to!int;
	Node[] nodes = new Node[](n);
	foreach (ref node; nodes) {
		int l, r;
		readln.chomp.split.tie(l, r);
		node = Node(l, r);
	}
	long ans = 0;
	std.algorithm.sort!((a, b) => a.l < b.l)(nodes);
	for (int i = n / 2 - 2; i <= n / 2 + 2; ++i) {
		if (i < 0 || n <= i) {
			continue;
		}
		ans = max(ans, solve1(nodes, i, nodes[i].l));
		ans = max(ans, solve1(nodes, i, nodes[i].r));
		ans = max(ans, solve2(nodes, i, nodes[i].l));
		ans = max(ans, solve2(nodes, i, nodes[i].r));
	}
	std.algorithm.sort!((a, b) => a.r < b.r)(nodes);
	for (int i = n / 2 - 2; i <= n / 2 + 2; ++i) {
		if (i < 0 || n <= i) {
			continue;
		}
		ans = max(ans, solve1(nodes, i, nodes[i].l));
		ans = max(ans, solve1(nodes, i, nodes[i].r));
		ans = max(ans, solve2(nodes, i, nodes[i].l));
		ans = max(ans, solve2(nodes, i, nodes[i].r));
	}
	ans.writeln;
}

void tie(R, Args...)(R arr, ref Args args)
		if (isRandomAccessRange!R || isArray!R)
in
{
	assert (arr.length == args.length);
}
body
{
	foreach (i, ref v; args) {
		alias T = typeof(v);
		v = arr[i].to!T;
	}
}

void verbose(Args...)(in Args args)
{
	stderr.write("[");
	foreach (i, ref v; args) {
		if (i) stderr.write(", ");
		stderr.write(v);
	}
	stderr.writeln("]");
}
