#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
using namespace std;
using Int = long long;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<55)+1e9; // ~ 3.6 * 1e16
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
using T = tuple<Int,Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
ostream& operator<<(ostream& o,T t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){Int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){Int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}

Int solve(vector<T> A, vector<T> B, int turn = 0){
  //pr(A);
  //pr(B);
  set<Int> used;
  Int n = A.size();
  A.push_back(T(-1,-1,-1));
  B.push_back(T(-1,-1,-1));
  
  auto calcDis = [](Int l,Int r, Int x){
    if(x < l) return l - x;
    if(x > r) return x - r;
    return 0LL;
  };

  auto checkType = [](Int l,Int r, Int x){
    if(x < l) return 0;
    if(x > r) return 1;
    return 2;
  };


  Int res = 0;
  Int x = 0;
  Int a = 0, b = 0;
  while(a < n || b < n){
    Int al, ar, ai; tie(al,ar,ai) = A[a];
    Int bl, br, bi; tie(bl,br,bi) = B[b];
    if(used.count(ai)) {a++; continue;}
    if(used.count(bi)) {b++; continue;}
    Int disa = calcDis(al, ar, x);
    Int disb = calcDis(bl, br, x);
    if(a == n) disa = 0;
    if(b == n) disb = 0;
    
    if(disa == 0 && disb == 0) a < b? a++:b++;
    else if(turn == 0){
      res += disa;
      int type = checkType(al, ar, x);
      if(type == 0) x = al;
      if(type == 1) x = ar;
      used.insert(ai);
      turn = !turn;
    }
    else {
      res += disb;
      int type = checkType(bl, br, x);
      if(type == 0) x = bl;
      if(type == 1) x = br;
      used.insert(bi);
      turn = !turn;
    }
  }
  res += abs(x);
  return res;
}

signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  
  Int n;
  cin>>n;
  vector<P> tmp(n);
  cin>>tmp;
  vector<T> A,B;
  for(Int i=0;i<n;i++) A.push_back(T(tmp[i].first, tmp[i].second,i));
  for(Int i=0;i<n;i++) B.push_back(T(tmp[i].second, tmp[i].first,i));
  sort(A.begin(), A.end(),greater<T>());
  sort(B.begin(), B.end());
  for(Int i=0;i<n;i++){
    Int r, l, idx; tie(r, l ,idx) = B[i];
    B[i] = T(l, r, idx);
  }
  Int a = solve(A,B,0);
  Int b = solve(A,B,1);
  Int ans = max(a, b);
  cout<<ans<<endl;
  //  pr(a,b);
  return 0;
}


Measured memory_bytes: 20520