output_description: Print the total distance traveled by Takahashi throughout the game when
  Takahashi and Aoki acts as above. It is guaranteed that K is always an integer
  when L_i,R_i are integers.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      L_1 R_1
      :
      L_N R_N
attempt: import sys
  
  sys.setrecursionlimit(10**7)  # 再帰関数の上限,10**5以上の場合python
  import math
  from copy import copy, deepcopy
  from copy import deepcopy as dcp
  from operator import itemgetter
  from bisect import bisect_left, bisect, bisect_right  # 2分探索
  
  # bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
  from collections import deque, defaultdict
  
  # deque(l), pop(), append(x), popleft(), appendleft(x)
  # q.rotate(n)で → にn回ローテート
  from collections import Counter  # 文字列を個数カウント辞書に、
  
  # S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
  from itertools import accumulate, combinations, permutations, product  # 累積和
  
  # list(accumulate(l))
  from heapq import heapify, heappop, heappush
  
  # heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
  from functools import reduce, lru_cache  # pypyでもうごく
  
  # @lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
  from decimal import Decimal
  
  
  def input():
      x = sys.stdin.readline()
      return x[:-1] if x[-1] == "\n" else x
  
  
  def printe(*x):
      print("## ", *x, file=sys.stderr)
  
  
  def printl(li):
      _ = print(*li, sep="\n") if li else None
  
  
  def argsort(s, return_sorted=False):
      inds = sorted(range(len(s)), key=lambda k: s[k])
      if return_sorted:
          return inds, [s[i] for i in inds]
      return inds
  
  
  def alp2num(c, cap=False):
      return ord(c) - 97 if not cap else ord(c) - 65
  
  
  def num2alp(i, cap=False):
      return chr(i + 97) if not cap else chr(i + 65)
  
  
  def matmat(A, B):
      K, N, M = len(B), len(A), len(B[0])
      return [
          [sum([(A[i][k] * B[k][j]) for k in range(K)]) for j in range(M)]
          for i in range(N)
      ]
  
  
  def matvec(M, v):
      N, size = len(v), len(M)
      return [sum([M[i][j] * v[j] for j in range(N)]) for i in range(size)]
  
  
  def T(M):
      n, m = len(M), len(M[0])
      return [[M[j][i] for j in range(n)] for i in range(m)]
  
  
  def binr(x):
      return bin(x)[2:]
  
  
  def bitcount(x):  # xは64bit整数
      x = x - ((x >> 1) & 0x5555555555555555)
      x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
      x = (x + (x >> 4)) & 0x0F0F0F0F0F0F0F0F
      x += x >> 8
      x += x >> 16
      x += x >> 32
      return x & 0x7F
  
  
  def main():
      # C - Interval Game
      mod = 1000000007
      # w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え
  
      N = int(input())
      # N, K = map(int, input().split())
      # A = tuple(map(int, input().split())) #1行ベクトル
      # L = tuple(int(input()) for i in range(N)) #改行ベクトル
      S = tuple(tuple(map(int, input().split())) for i in range(N))  # 改行行列
      base = N
      ls = []
      rs = []
      for i, (l, r) in enumerate(S):
          heappush(ls, -l * base + i)
          heappush(rs, r * base + i)
  
      dset = set()
      cur = 0
      tot = 0
      f = 0
      lsc = ls.copy()
      rsc = rs.copy()
      while ls and rs:
          while ls:
              l, i = divmod(heappop(ls), base)
              l *= -1
              if i in dset:
                  dset.remove(i)
              elif cur < l:
                  tot += l - cur
                  dset.add(i)
                  cur = l
                  break
              else:
                  f = 1
                  break
          if f:
              break
          while rs:
              r, i = divmod(heappop(rs), base)
              if i in dset:
                  dset.remove(i)
              elif cur > r:
                  tot += cur - r
                  cur = r
                  dset.add(i)
                  break
              else:
                  f = 1
                  break
          if f:
              break
      tot += abs(cur)
  
      ls = lsc
      rs = rsc
      dset = set()
      cur = 0
      tot2 = 0
      f = 0
      while ls and rs:
          while rs:
              r, i = divmod(heappop(rs), base)
              if i in dset:
                  dset.remove(i)
              elif cur > r:
                  tot2 += cur - r
                  cur = r
                  dset.add(i)
                  break
              else:
                  f = 1
                  break
  
          if f:
              break
          while ls:
              l, i = divmod(heappop(ls), base)
              l *= -1
              if i in dset:
                  dset.remove(i)
              elif cur < l:
                  tot2 += l - cur
                  dset.add(i)
                  cur = l
                  break
              else:
                  f = 1
                  break
              if f:
                  break
      tot2 += abs(cur)
  
      print(max(tot, tot2))
  
  
  if __name__ == "__main__":
      main()
  
problem_description: Statement
  
  Takahashi and Aoki will play a game with a number line and some segments.
  Takahashi is standing on the number line and he is initially at coordinate 0.
  Aoki has N segments. The i-th segment is [L_i,R_i], that is, a segment
  consisting of points with coordinates between L_i and R_i (inclusive).
  
  The game has N steps. The i-th step proceeds as follows:
  
    * First, Aoki chooses a segment that is still not chosen yet from the N segments and tells it to Takahashi.
    * Then, Takahashi walks along the number line to some point within the segment chosen by Aoki this time.
  
  After N steps are performed, Takahashi will return to coordinate 0 and the
  game ends.
  
  Let K be the total distance traveled by Takahashi throughout the game. Aoki
  will choose segments so that K will be as large as possible, and Takahashi
  walks along the line so that K will be as small as possible. What will be the
  value of K in the end?
samples: [{"input": "3\n    -5 1\n    3 7\n    -4 -2", "output": "10\n    \n\nOne possible sequence of actions of Takahashi and Aoki is as follows:\n\n  * Aoki chooses the first segment. Takahashi moves from coordinate 0 to -4, covering a distance of 4.\n  * Aoki chooses the third segment. Takahashi stays at coordinate -4.\n  * Aoki chooses the second segment. Takahashi moves from coordinate -4 to 3, covering a distance of 7.\n  * Takahashi moves from coordinate 3 to 0, covering a distance of 3.\n\nThe distance covered by Takahashi here is 14 (because Takahashi didn't move\noptimally). It turns out that if both players move optimally, the distance\ncovered by Takahashi will be 10.\n\n* * *"}, {"input": "3\n    1 2\n    3 4\n    5 6", "output": "12\n    \n\n* * *"}, {"input": "5\n    -2 0\n    -2 0\n    7 8\n    9 10\n    -2 -1", "output": "34"}]