# ref https://atcoder.jp/contests/agc025/submissions/7307839

import numpy as np



def main():

    n = int(eval(input()))

    L, R = [], []

    for i in range(n):

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

        L.append(l)

        R.append(r)

    ll = np.array(L); ll.sort(); ll = ll[::-1]

    rr = np.array(R); rr.sort()



    lll = ll.cumsum()

    rrr = rr.cumsum()



    x = (lll - rrr).max()

    y = (lll[1:] - rrr[:-1]).max()

    z = (lll[:-1] - rrr[1:]).max()



    print((2 * max(x, y, z)))

if __name__ == '__main__':

    main()
# ref https://atcoder.jp/contests/agc025/submissions/2609185

def main():

    n = int(eval(input()))

    L, R = [0], [0]

    for i in range(n):

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

        L.append(l)

        R.append(r)

    L.sort()

    L.reverse()

    R.sort()



    res = 0

    for i in range(n + 1):

        if L[i] > R[i]:

            res += 2 * (L[i] - R[i])



    print(res)

if __name__ == '__main__':

    main()
# ref https://atcoder.jp/contests/agc025/submissions/7307839
import numpy as np


def main():
    n = int(eval(input()))
    L, R = [], []
    for i in range(n):
        l, r = list(map(int, input().split()))
        L.append(l)
        R.append(r)
    ll = np.array(L)
    ll.sort()
    ll = ll[::-1]
    rr = np.array(R)
    rr.sort()
    lll = ll.cumsum()
    rrr = rr.cumsum()
    x = (lll - rrr).max()
    y = (lll[1:] - rrr[:-1]).max()
    z = (lll[:-1] - rrr[1:]).max()
    print((2 * max(x, y, z)))


if __name__ == "__main__":
    main()

# ref https://atcoder.jp/contests/agc025/submissions/2609185
def main():
    n = int(eval(input()))
    L, R = [0], [0]
    for i in range(n):
        l, r = list(map(int, input().split()))
        L.append(l)
        R.append(r)
    L.sort()
    L.reverse()
    R.sort()
    res = 0
    for i in range(n + 1):
        if L[i] > R[i]:
            res += 2 * (L[i] - R[i])
    print(res)


if __name__ == "__main__":
    main()

-# ref https://atcoder.jp/contests/agc025/submissions/7307839 -import numpy as np - - +# ref https://atcoder.jp/contests/agc025/submissions/2609185 -    L, R = [], [] +    L, R = [0], [0] -    ll = np.array(L) -    ll.sort() -    ll = ll[::-1] -    rr = np.array(R) -    rr.sort() -    lll = ll.cumsum() -    rrr = rr.cumsum() -    x = (lll - rrr).max() -    y = (lll[1:] - rrr[:-1]).max() -    z = (lll[:-1] - rrr[1:]).max() -    print((2 * max(x, y, z))) +    L.sort() +    L.reverse() +    R.sort() +    res = 0 +    for i in range(n + 1): +        if L[i] > R[i]: +            res += 2 * (L[i] - R[i]) +    print(res)