from heapq import heappush, heappop

N = int(eval(input()))

S = []

for i in range(N):

    l, r = list(map(int, input().split()))

    S.append((l, r))

S.sort()



if all(l <= 0 <= r for l, r in S):

    print((0))

    exit(0)



que = []

P = []

Q = [l for l, r in S]

Q.reverse()

ans = 0

a = b = 0

p = 0

for i in range(N+1):

    if i < N:

        l, r = S[i]

    while que and que[0] <= l:

        P.append(heappop(que))

    cnt = min(len(P), len(Q))

    while p < cnt:

        a += P[p]

        b += Q[p]

        p += 1

    ans = max(ans, abs(a-b)*2)

    if len(P) < len(Q):

        b2 = b + Q[cnt]

        ans = max(ans, abs(a-b2)*2)

    elif len(P) > len(Q):

        a2 = a + P[cnt]

        ans = max(ans, abs(a2-b)*2)

    heappush(que, r)

    if cnt == len(Q) > 0:

        a -= P[cnt-1]

        b -= Q[cnt-1]

    if i < N:

        Q.pop()

print(ans)

from heapq import heappush, heappop

N = int(eval(input()))

S = []

for i in range(N):

    l, r = list(map(int, input().split()))

    S.append((l, r))



if all(l <= 0 <= r for l, r in S):

    print((0))

    exit(0)



P = sorted(r for l, r in S)

Q = sorted(l for l, r in S)

L = R = 0

ans = 0

for i in range(N):

    if not i < N-1-i:

        break

    L += P[i]

    R += Q[N-1-i]

    ans = max(ans, abs(R - L)*2)

    if i+1 < N-1-i:

        ans = max(ans, abs(R - L - P[i+1])*2)

    if i < N-1-i-1:

        ans = max(ans, abs(R + Q[N-1-i-1] - L)*2)

print(ans)
from heapq import heappush, heappop

N = int(eval(input()))
S = []
for i in range(N):
    l, r = list(map(int, input().split()))
    S.append((l, r))
S.sort()
if all(l <= 0 <= r for l, r in S):
    print((0))
    exit(0)
que = []
P = []
Q = [l for l, r in S]
Q.reverse()
ans = 0
a = b = 0
p = 0
for i in range(N + 1):
    if i < N:
        l, r = S[i]
    while que and que[0] <= l:
        P.append(heappop(que))
    cnt = min(len(P), len(Q))
    while p < cnt:
        a += P[p]
        b += Q[p]
        p += 1
    ans = max(ans, abs(a - b) * 2)
    if len(P) < len(Q):
        b2 = b + Q[cnt]
        ans = max(ans, abs(a - b2) * 2)
    elif len(P) > len(Q):
        a2 = a + P[cnt]
        ans = max(ans, abs(a2 - b) * 2)
    heappush(que, r)
    if cnt == len(Q) > 0:
        a -= P[cnt - 1]
        b -= Q[cnt - 1]
    if i < N:
        Q.pop()
print(ans)

from heapq import heappush, heappop

N = int(eval(input()))
S = []
for i in range(N):
    l, r = list(map(int, input().split()))
    S.append((l, r))
if all(l <= 0 <= r for l, r in S):
    print((0))
    exit(0)
P = sorted(r for l, r in S)
Q = sorted(l for l, r in S)
L = R = 0
ans = 0
for i in range(N):
    if not i < N - 1 - i:
        break
    L += P[i]
    R += Q[N - 1 - i]
    ans = max(ans, abs(R - L) * 2)
    if i + 1 < N - 1 - i:
        ans = max(ans, abs(R - L - P[i + 1]) * 2)
    if i < N - 1 - i - 1:
        ans = max(ans, abs(R + Q[N - 1 - i - 1] - L) * 2)
print(ans)

-S.sort() -que = [] -P = [] -Q = [l for l, r in S] -Q.reverse() +P = sorted(r for l, r in S) +Q = sorted(l for l, r in S) +L = R = 0 -a = b = 0 -p = 0 -for i in range(N + 1): -    if i < N: -        l, r = S[i] -    while que and que[0] <= l: -        P.append(heappop(que)) -    cnt = min(len(P), len(Q)) -    while p < cnt: -        a += P[p] -        b += Q[p] -        p += 1 -    ans = max(ans, abs(a - b) * 2) -    if len(P) < len(Q): -        b2 = b + Q[cnt] -        ans = max(ans, abs(a - b2) * 2) -    elif len(P) > len(Q): -        a2 = a + P[cnt] -        ans = max(ans, abs(a2 - b) * 2) -    heappush(que, r) -    if cnt == len(Q) > 0: -        a -= P[cnt - 1] -        b -= Q[cnt - 1] -    if i < N: -        Q.pop() +for i in range(N): +    if not i < N - 1 - i: +        break +    L += P[i] +    R += Q[N - 1 - i] +    ans = max(ans, abs(R - L) * 2) +    if i + 1 < N - 1 - i: +        ans = max(ans, abs(R - L - P[i + 1]) * 2) +    if i < N - 1 - i - 1: +        ans = max(ans, abs(R + Q[N - 1 - i - 1] - L) * 2)