#include<bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll inf = 1e18;
using P = pair<ll, ll>;
const int N = 1e5;

// #undef DEBUG
// #define DEBUG
/// {{{ DEBUG --- ///
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { if(&o == &cerr) { o << '{'; for(size_t i = 0; i < v.size(); i++) o << v[i] << (i + 1 != v.size() ? ", " : ""); o << "}"; } else { for(size_t i = 0; i < v.size(); i++) o << v[i] << (i + 1 != v.size() ? " " : ""); } return o; }
#ifdef DEBUG
#ifdef USE_COUT
#define dump(...) (cout<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<make_tuple(__VA_ARGS__)<<"\n")
#else
#define dump(...) (cerr<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<make_tuple(__VA_ARGS__)<<"\n")
#endif
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":", ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream &o, tuple<T...> const &t){ o << "("; _ot<0>(o, t); o << ")"; return o; }
#else
#define dump(...) (0)
#endif
/// }}}--- ///

// use 2^i size by yourself
// otherwise, maybe, it needs exchange law
/// --- SegmentTree Library {{{ ///

/*
   struct Monoid {
   using T = _underlying_set_;
   static T op(const T& a, const T& b) { return _a_op_b_; }
   static constexpr T identity() { return _identity_element_; }
   };
 */

template<class Monoid>
struct SegTree {
private:
  using T = typename Monoid::T;
  const int n;
  vector<T> data;
  void propTo(int i) { data[i] = Monoid::op(data[2 * i], data[2 * i + 1]); }

public:
  SegTree(int n, const T& v = Monoid::identity())
    : n(n),data(2 * n, v) {}

  template <class InputIt>
    SegTree(InputIt first, InputIt last)
    : n(distance(first, last)), data(2 * n, Monoid::identity()) {
      copy(first, last, begin(data) + n);
      // たぶん深いところから更新するため
      for(int i = n - 1; i > 0; i--) propTo(i);
    }

  void set(int i, const T& v) {
    data[i += n] = v;
    while(i >>= 1) propTo(i);
  }

  T get(int i) { return data[i + n]; }

  T query(int l, int r) {
    l = max(0, l); r = min(r, n);
    T tmpL = Monoid::identity(), tmpR = Monoid::identity();
    for(l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if(l & 1) tmpL = Monoid::op(tmpL, data[l++]);
      if(r & 1) tmpR = Monoid::op(data[--r], tmpR);
    }
    return Monoid::op(tmpL, tmpR);
  }
};

struct RMQMonoid {
  using T = P;
  static T op(const T& a, const T& b) { return std::min(a, b); }
  static constexpr T identity() { return P(inf, inf); }
};
struct RSQMonoid {
  using T = long long;
  static T op(const T& a, const T& b) { return a + b; }
  static constexpr T identity() { return 0; }
};
struct RMaxQMonoid {
  using T = P;
  static T op(const T& a, const T& b) { return std::max(a, b); }
  static constexpr T identity() { return P(-inf, -inf); }
};

using RMQ = SegTree<RMQMonoid>;
using RSQ = SegTree<RSQMonoid>;
using RMaxQ = SegTree<RMaxQMonoid>;

/// }}}--- ///


RMaxQ L(N);
RMQ R(N);

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n;
  cin >> n;
  dump(3);
  for(int i = 0; i < n; i++) {
    int l, r; cin >> l >> r;
    dump(l, r);
    L.set(i, P(l, i));
    R.set(i, P(r, i));
  }
  dump(L.get(0).first);
  dump(L.query(0, 1).first);
  auto L2 = L;
  auto R2 = R;
  int u = 0;
  ll now = 0;
  ll ans = 0;
  dump(2);
  for(int i = 0; i < n; i++) {
    u ^= 1;
    auto t = u ? L.query(0, n) : R.query(0, n);
    dump(t.first, t.second);
    L.set(t.second, P(-inf, -inf));
    R.set(t.second, P(inf, inf));
    int on;
    if(!u) on = min(now, t.first);
    else on = max(now, t.first);
    ans += abs(now - on);
    now = on;
  }
  ans += abs(now);
  now = 0;
  u = 1;
  ll res = 0;
  dump(4);
  for(int i = 0; i < n; i++) {
    u ^= 1;
    auto t = u ? L2.query(0, n) : R2.query(0, n);
    L2.set(t.second, P(-inf, -inf));
    R2.set(t.second, P(inf, inf));
    int on;
    if(!u) on = min(now, t.first);
    else on = max(now, t.first);
    res += abs(now - on);
    now = on;
  }
  res += abs(now);
  dump(res, ans);
  cout << max(res, ans) << endl;
}




Measured memory_bytes: 14848