#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9 + 7

def solve(f):
    n = f.read_int()

    lside = []
    rside = []
    for ind in xrange(n):
        l, r = f.read_int_list()
        heapq.heappush(lside, (r, -l, ind))
        heapq.heappush(rside, (-l, r, ind))
    used = collections.defaultdict(bool)
    lside_dup = lside[:]
    rside_dup = rside[:]

    ans1 = 0
    cur = 0
    for i in xrange(n):
        l, r = 0, 0
        if i%2 == 0:
            while True:
                a, b, ind = heapq.heappop(lside)
                l, r = -b, a
                if not used[ind]:
                    used[ind] = True
                    break
        else:
            while True:
                a, b, ind = heapq.heappop(rside)
                l, r = -a, b
                if not used[ind]:
                    used[ind] = True
                    break

        if l <= cur <= r:
            pass
        elif cur < l:
            ans1 += l-cur
            cur = l
        else:
            ans1 += cur-r
            cur = r
    ans1 += abs(cur)

    lside = lside_dup
    rside = rside_dup
    used = collections.defaultdict(bool)
    ans2 = 0
    cur = 0
    for i in xrange(n):
        l, r = 0, 0
        if i%2 == 1:
            while True:
                a, b, ind = heapq.heappop(lside)
                l, r = -b, a
                if not used[ind]:
                    used[ind] = True
                    break
        else:
            while True:
                a, b, ind = heapq.heappop(rside)
                l, r = -a, b
                if not used[ind]:
                    used[ind] = True
                    break

        if l <= cur <= r:
            pass
        elif cur < l:
            ans2 += l-cur
            cur = l
        else:
            ans2 += cur-r
            cur = r
    ans2 += abs(cur)

    return max(ans1, ans2)


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)


Measured memory_bytes: 42212