N = int(eval(input()))

 

intervals = tuple(tuple(map(int,input().split())) for _ in range(N))

 

L = sorted((l for l,r in intervals))

R = sorted((r for l,r in intervals), reverse=True)

 

def helper(L,R,turn):

  x = 0

  cost = 0

  T = [L,None,R]

  while True:

    y = T[turn+1].pop()

 

    if turn*(y-x) < 0:

      cost += abs(x-y)

      x = y

    else:

      break

    turn *= -1

  cost += abs(x)

  return cost



print((max(helper(L.copy(), R.copy(), t) for t in (-1,1))))
N = int(eval(input()))

L,R = [None]*N,[None]*N

for i in range(N):

  L[i],R[i] = list(map(int,input().split()))

L.append(0)

R.append(0)

L.sort(reverse=True)

R.sort()



def it():

  for l,r in zip(L,R):

    if r < l:

      yield 2*(l-r)

    else:

      return



print((sum(it())))
N = int(eval(input()))
intervals = tuple(tuple(map(int, input().split())) for _ in range(N))
L = sorted((l for l, r in intervals))
R = sorted((r for l, r in intervals), reverse=True)


def helper(L, R, turn):
    x = 0
    cost = 0
    T = [L, None, R]
    while True:
        y = T[turn + 1].pop()
        if turn * (y - x) < 0:
            cost += abs(x - y)
            x = y
        else:
            break
        turn *= -1
    cost += abs(x)
    return cost


print((max(helper(L.copy(), R.copy(), t) for t in (-1, 1))))

N = int(eval(input()))
L, R = [None] * N, [None] * N
for i in range(N):
    L[i], R[i] = list(map(int, input().split()))
L.append(0)
R.append(0)
L.sort(reverse=True)
R.sort()


def it():
    for l, r in zip(L, R):
        if r < l:
            yield 2 * (l - r)
        else:
            return


print((sum(it())))

-intervals = tuple(tuple(map(int, input().split())) for _ in range(N)) -L = sorted((l for l, r in intervals)) -R = sorted((r for l, r in intervals), reverse=True) +L, R = [None] * N, [None] * N +for i in range(N): +    L[i], R[i] = list(map(int, input().split())) +L.append(0) +R.append(0) +L.sort(reverse=True) +R.sort() -def helper(L, R, turn): -    x = 0 -    cost = 0 -    T = [L, None, R] -    while True: -        y = T[turn + 1].pop() -        if turn * (y - x) < 0: -            cost += abs(x - y) -            x = y +def it(): +    for l, r in zip(L, R): +        if r < l: +            yield 2 * (l - r) -            break -        turn *= -1 -    cost += abs(x) -    return cost +            return -print((max(helper(L.copy(), R.copy(), t) for t in (-1, 1)))) +print((sum(it())))