#include <iostream>
#include <set>
#include <map>
#include <array>
#include <cassert>
#include <cstring>
#include <functional>
#include <vector>
#include <list>
#include <algorithm>

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define eb emplace_back
#define pb push_back
#define mp make_pair

template <typename T>
bool uax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template <typename T>
bool uin(T& a, T b) { if (b < a) { a = b; return true; } return false; }

using namespace std;

typedef pair<int, int> pii;
typedef vector<pii> vpi;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef list<int> li;
typedef vector<li> vli;
typedef vector<vpi> vvpi;
typedef long long i64;

const int inf = 1e9;

int sum_base(int n, int b = 10) {
  int s = 0;
  while (n) { s += n % b; n /= b; }
  return s;
}

void solve_a() {
  int n; cin >> n;
  int r = inf;
  fore(a, 1, n - 1) uin(r, sum_base(a) + sum_base(n - a));
  cout << r << endl;
}

void solve_b() {
  int n; cin >> n;
  i64 a, b; cin >> a >> b;
  i64 k; cin >> k;
  const int mod = 998244353;
  auto mul = [] (int a, int b) {
    return a * 1ll * b % mod;
  };
  auto sum = [] (int a, int b) {
    if ((a += b) >= mod) a -= mod;
    return a;
  };
  auto power = [&] (int a, i64 n) {
    int r = 1; while (n) {
      if (n&1) r = mul(r, a);
      if (n/=2) a = mul(a, a);
    } return r;
  };
  vi ff(n + 1, 1);
  vi fi(n + 1, 1);
  fore(i, 1, n) ff[i] = mul(ff[i-1], i);
  fi[n] = power(ff[n], mod - 2);
  for (int i = n - 1; i >= 1; --i) fi[i] = mul(fi[i + 1], i + 1);
  auto get3 = [&] (int n, int i, int j, int k) {
    return mul(mul(mul(ff[n], fi[i]), fi[j]), fi[k]);
  };
  auto get2 = [&] (int n, int i, int j) {
    return mul(mul(ff[n], fi[i]), fi[j]);
  };
  vi cnk(n + 1, 1);
  fore(i, 1, n) cnk[i] = sum(cnk[i-1], get2(n, i, n - i));
  int r = 0;
  fore(i, 0, n) {
    i64 sk = k - a * i;
    if (sk >= 0 && sk % b == 0) {
      i64 j = sk / b;
      if (j <= n) {
        r = sum(r, mul(get2(n, i, n - i), get2(n, j, n - j)));
      }
    }
  }
  cout << r << endl;
}

vvi a, u;
vpi zz;
int n;

bool ok2(int i, int j) {
  return 0 <= i && i < 2 * n && 0 <= j && j < 2 * n;
};

bool dfs(int ij, char c) {
  int i = ij / (2 * n);
  int j = ij % (2 * n);
  if (!u[i][j]) return true;
  if (a[i][j]) return a[i][j] == c;
  a[i][j] = c;
  forn(t, zz.size()) {
    int ni = i + zz[t].fi, nj = j + zz[t].se;
    if (!ok2(ni, nj)) continue;
    if (!dfs(ni * (2 * n) + nj, 3 - c)) return false;
  }
  return true;
};

bool dfs(int i, int j, int c) {
  return dfs(i * 2 * n + j, c);
}

bool solve_d2(int n, int d0, int d1) {
  ::n = n;
  vpi z0, z1;
  fore(i, -2 * n + 1, 2 * n - 1) {
    fore(j, -2 * n + 1, 2 * n - 1) {
      if (i * i + j * j == d0) z0.eb(i, j);
      if (i * i + j * j == d1) z1.eb(i, j);
    }
  }
  a = vvi(2 * n, vi(2 * n, 0));
  u = vvi(2 * n, vi(2 * n, 1));
  zz = z0;
  forn(i, 2 * n) forn(j, 2 * n) if (a[i][j] == 0) dfs(i, j, 1);
  vi c0(2, 0);
  forn(i, 2 * n) forn(j, 2 * n) c0[a[i][j] - 1] += 1;
  int c0d = c0[0] > c0[1] ? 1 : 2;
  forn(i, 2 * n) forn(j, 2 * n) if (a[i][j] != c0d) u[i][j] = 0;
  forn(i, 2 * n) forn(j, 2 * n) a[i][j] = 0;
  zz = z1;
  forn(i, 2 * n) forn(j, 2 * n) if (u[i][j] && a[i][j] == 0) dfs(i, j, 1);
  vi c1(2, 0);
  forn(i, 2 * n) forn(j, 2 * n) if (u[i][j]) c1[a[i][j] - 1] += 1;
  int c1d = c1[0] > c1[1] ? 1 : 2;
  vpi r;
  forn(i, 2 * n) forn(j, 2 * n) if (u[i][j] && a[i][j] == c1d) r.eb(i, j);
  assert(r.size() >= n * n);
  // if (r.size() < n * n) return false;
  r.resize(n * n);
  for (auto e: r) cout << e.fi << ' ' << e.se << endl;
  return true;
}

bool solve_d(int n, int d0, int d1) {
  vpi z;
  fore(i, -2 * n + 1, 2 * n - 1) {
    fore(j, -2 * n + 1, 2 * n - 1) {
      if (i * i + j * j == d0 || i * i + j * j == d1) {
        z.eb(i, j);
      }
    }
  }
  auto ok2 = [&] (int i, int j) {
    return 0 <= i && i < 2 * n && 0 <= j && j < 2 * n;
  };
  vpi order;
  fore(i, 0, 2 * n - 1) {
    fore(j, 0, 2 * n - 1) {
      order.eb(i, j);
    }
  }
  do {
    vvi a(2 * n, vi(2 * n, 0));
    vpi r;
    for (auto eo: order) {
      int i = eo.fi, j = eo.se;
      if (r.size() >= n * n) break;
      bool ok = true;
      for(auto e: z) {
        if (ok2(i + e.fi, j + e.se) && a[i + e.fi][j + e.se]) {
          ok = false; break;
        }
      }
      if (ok) {
        a[i][j] = 1;
        r.eb(i, j);
      }
    }
    if (r.size() == n * n) {
      // for (auto e: r) cout << e.fi << ' ' << e.se << endl;
      return true;
    }
    random_shuffle(all(order));
  } while (true);
  return false;
}

void solve_c() {
  int n; n = 100000; cin >> n;
  vpi a(n); forn(i, n) {
    // a[i].fi = rand()%(int)(2e5+1)-1e5; a[i].se = rand()%(int)(2e5+1)-1e5; if (a[i].fi < a[i].se) swap(a[i].fi, a[i].se);
    cin >> a[i].fi >> a[i].se;
  }
  vi b(n), c(n);
  forn(i, n) b[i] = c[i] = i;
  sort(all(b), [&] (int i, int j) { return pii(a[i].se, i) < pii(a[j].se, j); });
  sort(all(c), [&] (int i, int j) { return pii(a[i].fi, i) > pii(a[j].fi, j); });
  b.pb(n); c.pb(n);
  i64 ans = 0;
  forn(st, 2) {
    vi u(n, 1);
    int i = 0, j = 0, x = 0, t = st, y; i64 s = 0;
    forn(_, n) {
      int p;
      if (t) {
        do { p = b[i]; ++i; } while (!u[p]);
      } else {
        do { p = c[j]; ++j; } while (!u[p]);
      }
      assert(p != n);
      u[p] = 0;
      y = min(max(x, a[p].fi), a[p].se);
      s += abs(x - y); x = y; t = 1 - t;
    }
    s += abs(x);
    uax(ans, s);
  }
  {
    vi u(n, 1);
    int i = 0, j = 0, x = 0; i64 s = 0;
    forn(_, n) {
      int p0 = b[i], p1 = c[j];
      while (!u[p0]) { p0 = b[++i];} 
      while (!u[p1]) { p1 = c[++j];} 
      int y0 = min(max(x, a[p0].fi), a[p0].se);
      int y1 = min(max(x, a[p1].fi), a[p1].se);
      int p = abs(x - y0) > abs(x - y1) ? p0 : p1;
      u[p] = 0;
      int y = min(max(x, a[p].fi), a[p].se);
      s += abs(x - y); x = y;
    }
    s += abs(x);
    uax(ans, s);
  }
  cout << ans << endl;
}

int main() {
#ifdef HOME
  freopen("input.txt", "rt", stdin);
#endif
  solve_c();
  return 0;
}


Measured memory_bytes: 2184