Maksim walks on a Cartesian plane. Initially, he stands at the point $$$(0, 0)$$$ and in one move he can go to any of four adjacent points (left, right, up, down). For example, if Maksim is currently at the point $$$(0, 0)$$$, he can go to any of the following points in one move:   $$$(1, 0)$$$;  $$$(0, 1)$$$;  $$$(-1, 0)$$$;  $$$(0, -1)$$$. There are also $$$n$$$ distinct key points at this plane. The $$$i$$$-th point is $$$p_i = (x_i, y_i)$$$. It is guaranteed that $$$0 \le x_i$$$ and $$$0 \le y_i$$$ and there is no key point $$$(0, 0)$$$.Let the first level points be such points that $$$max(x_i, y_i) = 1$$$, the second level points be such points that $$$max(x_i, y_i) = 2$$$ and so on. Maksim wants to visit all the key points. But he shouldn't visit points of level $$$i + 1$$$ if he does not visit all the points of level $$$i$$$. He starts visiting the points from the minimum level of point from the given set.The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$ where $$$|v|$$$ is the absolute value of $$$v$$$.Maksim wants to visit all the key points in such a way that the total distance he walks will be minimum possible. Your task is to find this distance.If you are Python programmer, consider using PyPy instead of Python when you submit your code.

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of key points. Each of the next $$$n$$$ lines contains two integers $$$x_i$$$, $$$y_i$$$ ($$$0 \le x_i, y_i \le 10^9$$$) — $$$x$$$-coordinate of the key point $$$p_i$$$ and $$$y$$$-coordinate of the key point $$$p_i$$$. It is guaranteed that all the points are distinct and the point $$$(0, 0)$$$ is not in this set.

Print one integer — the minimum possible total distance Maksim has to travel if he needs to visit all key points in a way described above.

NoteThe picture corresponding to the first example: There is one of the possible answers of length $$$15$$$.The picture corresponding to the second example: There is one of the possible answers of length $$$9$$$.

                    const eps=1e-10;
                    besk=8000000000000000000;
                     label 1,2,33,44;
                 type
                     mas=array[-200000..2*1100000+1] of int64;
                  point=record x,y:int64 end;
                  point1=^point;
                  otr=record st,fin:point end;
var mask,kol1,stepp,mm,lavel,l,kol,dl,i1,j1,imin,step,i,j,k,m,n1,k1,w,mesto,pl1,pl2,pl3:longint;
len,t14,t24,t23,t13,p2,p3,p4,ttt,p1,ii,jj,kk,sum,pos1,pos2,tt,ans1,ans2,t,pp,ans,qq,ott,n,cc,nn,modul,p,ot,pmin,tmax,minf,gr1,gr2,tt1,nnn,d,raz1,raz2,v,s,st,q,gr:int64; flag1:boolean;
 zan:array[0..1000000] of boolean;
 cha:char;
z,b1,a1:array[-10..3000000] of int64;
ddleft,ddright:array[-100000..500000] of int64;
dd:array [-1..3000,-1..3000] of int64;
bbbb,cccc:array[0..100000] of extended;
 ss,ss1:string;
t1,t2,t3:extended;
xx,yy,x1,y1,x,y,mnog,stepen:array[-1000000..1000000] of int64;
left,right,zz,ll,rr,aa,ppp, c,a,b:mas; flag:boolean;  pl:longint;
function srav(i,j:longint):boolean;
begin if (a[i]<a[j]){or((a[i]=a[j])and(a1[i]<a1[j]))} then srav:=true else srav:=false;  end;
procedure sl (k,l,m:longint);  {k- dlina, l,m - nachalo dvuh blokov}
begin
i:=l;j:=m; flag:=true; step:=0;while flag do begin
if srav(i,j) then begin begin b[l+step]:=a[i];b1[l+step]:=a1[i];end;
inc(step);inc(i);
{writeln('step=',step,' i=',i);} end;
if not srav(i,j) then begin begin b[l+step]:=a[j];b1[l+step]:=a1[j];end;
inc(step);inc(j);end;
if  ((i>=l+k) or (j>=m+k)) then flag:=false;
end;
if(i>=l+k) then repeat b[l+step]:=a[j];b1[l+step]:=a1[j];inc(step);inc(j);until (j>=m+k);
if(j>=m+k) then repeat b[l+step]:=a[i];b1[l+step]:=a1[i];inc(step);inc(i);until (i>=l+k);
end;
procedure sort(var c:mas);

begin

k:=1; repeat
l:=1;m:=k+l; repeat sl(k,l,m); l:=l+2*k;m:=m+2*k; until (l>=n); k:=k*2;
for i:=1 to n do begin a[i]:=b[i];a1[i]:=b1[i]; end;
until (k>=n);
end;

 function  max(a,b:int64):int64;
 begin max:=a; if b>a then max:=b; end;
  function  min(a,b:int64):int64;
 begin min:=a; if b<a then min:=b; end;
function gcd(a,b:int64):int64; var p,t:int64;
begin if (a>0)and(b>0) then
   begin while (b>0) do begin t:=a mod b;a:=b;b:=t;    end;
    p:=a;
   end else if a=0 then p:=b else p:=a;
gcd:=p;
end;

function ff(gr:int64):int64;
var ot,aa,bb,cc:int64;
begin
  aa:=1; bb:=tt;  cc:=aa; ot:=0;
  while abs(aa-bb)>1 do
    begin
       cc:=(aa+bb) shr 1;
       if z[cc]<gr then aa:=cc else bb:=cc;

    end;
  { writeln(' cc= ',cc);
  } cc:=min(cc+3,pp+1);
   repeat dec(cc) until z[cc]<=gr;
   if gr=0 then cc:=0;
   ot:=cc;
  ff:=ot;
end;

function fff(gr:int64):int64;
var ot,aa,bb,cc:int64;
begin
  aa:=1; bb:=ttt;  cc:=aa; ot:=0;
  while abs(aa-bb)>1 do
    begin
       cc:=(aa+bb) shr 1;
       if zz[cc]<gr then aa:=cc else bb:=cc;

    end;
  { writeln(' cc= ',cc);
  } cc:=min(cc+3,pp+1);
   repeat dec(cc) until zz[cc]<=gr;
   if gr=0 then cc:=0;
   ot:=cc;
  fff:=ot;
end;

begin
  { assign(input,'input.txt');reset(input);
   assign(output,'output.txt');rewrite(output);
   }

    read(p);
    for i:=1 to p do read(x[i],y[i]);
   { p:=10;
    for i:=1 to p do if odd(i) then begin x[i]:=1000000-i; y[i]:=0;  end
    else begin y[i]:=1000000-i; x[i]:=0;  end;
    }

    if p=1 then begin writeln(x[1]+y[1]); goto 1;  end;

    for i:=1 to p do a[i]:=3000000000*max(x[i],y[i])+2*x[i]-y[i];
    for i:=1 to p do a1[i]:=i;

   {   for i:=1 to p do writeln(a[i],' ',a1[i]);
    }

   n:=1; repeat n:=n*2 until n>=p;
   for i:=p+1 to n do a[i]:=besk;
   sort(a);
  { for i:=1 to p do writeln(a[i],' ',a1[i]);
  } for i:=1 to p do b[a1[i]]:=i;
   for i:=1 to p do
     begin xx[i]:=x[a1[i]]; yy[i]:=y[a1[i]];   end;

   {  for i:=1 to p do writeln(xx[i],' ',yy[i]);
    }
     for i:=1 to p do if max(xx[i],yy[i])>max(xx[i-1],yy[i-1]) then
       begin inc(q); z[q]:=i;  end;
       inc(q); z[q]:=p+1;
     {  for i:=1 to q do write(z[i],' ');
       writeln;
      }
        for i:=1 to q do
          begin
        {    writeln('lavel= ',i);
            for j:=z[i-1] to z[i]-1 do  writeln('j= ',j,' point  ',xx[j],' ',yy[j]);
         }

          end;

       for i:=2 to p+1 do begin ddleft[i]:=besk; ddright[i]:=besk; end;

      for j:=2 to q do
    begin
       p1:=z[j-1]; p2:=z[j]-1;
       p3:=z[j-2]; p4:=z[j-1]-1;

      { writeln('step= ',j);
       }
       len:= abs(xx[p1]-xx[p2])+abs(yy[p1]-yy[p2]);
       t14:=abs(xx[p1]-xx[p4])+abs(yy[p1]-yy[p4]);
       t13:=abs(xx[p1]-xx[p3])+abs(yy[p1]-yy[p3]);

       t24:=abs(xx[p2]-xx[p4])+abs(yy[p2]-yy[p4]);
       t23:=abs(xx[p2]-xx[p3])+abs(yy[p2]-yy[p3]);

      { writeln(len,' t14= ',t14,' t13= ',t13,' t24= ',t24,' t23= ',t23);
        writeln;
       }

       ddleft[j]:=min(ddleft[j],len+ddleft[j-1]+t23);
       ddleft[j]:=min(ddleft[j],len+ddright[j-1]+t24);

       ddright[j]:=min(ddright[j],len+ddleft[j-1]+t13);
       ddright[j]:=min(ddright[j],len+ddright[j-1]+t14);

     { writeln('j= ',j,' ', ddleft[j],' ',ddright[j]);
      }
    end;

     writeln(min(ddleft[q],ddright[q]));

 1: close (output);
end.

program ProjectF;

uses
  Math;

type
  TLvl = record
    l, r, len: int64;
    d: array[1..4] of int64;
  end;

var
  n, i, LvlCount: longint;
  x, y, l, r: array[0..200000] of int64;
  Lvl: array[0..200000] of Tlvl;

procedure swap(var i, j: longint);
var
  d: int64;
begin
  d := x[i];
  x[i] := x[j];
  x[j] := d;
  d := y[i];
  y[i] := y[j];
  y[j] := d;
end;

function compare(i, j: longint): boolean;
begin
  if (max(x[i], y[i]) < max(x[j], y[j])) or ((max(x[i], y[i]) = max(x[j], y[j])) and ((x[i] < x[j]) or ((x[i] = x[j]) and (y[i] > y[j])))) then
    result := true
  else
    result := false;
end;

procedure sort(l, r: longint);
var
  i, j: longint;
begin
  i := l;
  j := r;
  x[0] := x[(l + r) div 2];
  y[0] := y[(l + r) div 2];
  repeat
    while compare(i, 0) do inc(i);
    while compare(0, j) do dec(j);
    if i <= j then begin
      swap(i, j);
      inc(i);
      dec(j);
    end;
  until i > j;
  if i < r then
    sort(i, r);
  if l < j then
    sort(l, j);
end;

function dist(i, j: longint): int64;
begin
  result := abs(x[i] - x[j]) + abs(y[i] - y[j]);
end;

begin
  read(n);
  for i := 1 to n do
    read(x[i], y[i]);

  sort(1, n);

  x[0] := 0;
  y[0] := 0;

  Lvl[0].l := 0;
  Lvl[0].r := 0;
  LvlCount := 1;
  Lvl[LvlCount].l := 1;
  for i := 2 to n do
    if max(x[i], y[i]) > max(x[i - 1], y[i - 1]) then begin
      with Lvl[LvlCount] do begin
        r := i - 1;
        len := dist(l, r);
        d[1] := dist(Lvl[LvlCount - 1].l, l);
        d[2] := dist(Lvl[LvlCount - 1].l, r);
        d[3] := dist(Lvl[LvlCount - 1].r, l);
        d[4] := dist(Lvl[LvlCount - 1].r, r);
      end;
      inc(LvlCount);
      Lvl[LvlCount].l := i;
    end;

  with Lvl[LvlCount] do begin
    r := n;
    len := dist(l, r);
    d[1] := dist(Lvl[LvlCount - 1].l, l);
    d[2] := dist(Lvl[LvlCount - 1].l, r);
    d[3] := dist(Lvl[LvlCount - 1].r, l);
    d[4] := dist(Lvl[LvlCount - 1].r, r);
  end;

  l[0] := 0;
  r[0] := 0;
  for i := 1 to LvlCount do begin
    l[i] := min(l[i - 1] + Lvl[i].d[2], r[i - 1] + Lvl[i].d[4]) + Lvl[i].len;
    r[i] := min(l[i - 1] + Lvl[i].d[1], r[i - 1] + Lvl[i].d[3]) + Lvl[i].len;
  end;

  write(min(l[LvlCount], r[LvlCount]));
end.

                    const eps=1e-10;
                    besk=8000000000000000000;
                     label 1,2,33,44;
                 type
                     mas=array[-200000..2*1100000+1] of int64;
                  point=record x,y:int64 end;
                  point1=^point;
                  otr=record st,fin:point end;
var mask,kol1,stepp,mm,lavel,l,kol,dl,i1,j1,imin,step,i,j,k,m,n1,k1,w,mesto,pl1,pl2,pl3:longint;
len,t14,t24,t23,t13,p2,p3,p4,ttt,p1,ii,jj,kk,sum,pos1,pos2,tt,ans1,ans2,t,pp,ans,qq,ott,n,cc,nn,modul,p,ot,pmin,tmax,minf,gr1,gr2,tt1,nnn,d,raz1,raz2,v,s,st,q,gr:int64; flag1:boolean;
 zan:array[0..1000000] of boolean;
 cha:char;
z,b1,a1:array[-10..3000000] of int64;
ddleft,ddright:array[-100000..500000] of int64;
dd:array [-1..3000,-1..3000] of int64;
bbbb,cccc:array[0..100000] of extended;
 ss,ss1:string;
t1,t2,t3:extended;
xx,yy,x1,y1,x,y,mnog,stepen:array[-1000000..1000000] of int64;
left,right,zz,ll,rr,aa,ppp, c,a,b:mas; flag:boolean;  pl:longint;
function srav(i,j:longint):boolean;
begin if (a[i]<a[j]){or((a[i]=a[j])and(a1[i]<a1[j]))} then srav:=true else srav:=false;  end;
procedure sl (k,l,m:longint);  {k- dlina, l,m - nachalo dvuh blokov}
begin
i:=l;j:=m; flag:=true; step:=0;while flag do begin
if srav(i,j) then begin begin b[l+step]:=a[i];b1[l+step]:=a1[i];end;
inc(step);inc(i);
{writeln('step=',step,' i=',i);} end;
if not srav(i,j) then begin begin b[l+step]:=a[j];b1[l+step]:=a1[j];end;
inc(step);inc(j);end;
if  ((i>=l+k) or (j>=m+k)) then flag:=false;
end;
if(i>=l+k) then repeat b[l+step]:=a[j];b1[l+step]:=a1[j];inc(step);inc(j);until (j>=m+k);
if(j>=m+k) then repeat b[l+step]:=a[i];b1[l+step]:=a1[i];inc(step);inc(i);until (i>=l+k);
end;
procedure sort(var c:mas);

begin

k:=1; repeat
l:=1;m:=k+l; repeat sl(k,l,m); l:=l+2*k;m:=m+2*k; until (l>=n); k:=k*2;
for i:=1 to n do begin a[i]:=b[i];a1[i]:=b1[i]; end;
until (k>=n);
end;

 function  max(a,b:int64):int64;
 begin max:=a; if b>a then max:=b; end;
  function  min(a,b:int64):int64;
 begin min:=a; if b<a then min:=b; end;
function gcd(a,b:int64):int64; var p,t:int64;
begin if (a>0)and(b>0) then
   begin while (b>0) do begin t:=a mod b;a:=b;b:=t;    end;
    p:=a;
   end else if a=0 then p:=b else p:=a;
gcd:=p;
end;

function ff(gr:int64):int64;
var ot,aa,bb,cc:int64;
begin
  aa:=1; bb:=tt;  cc:=aa; ot:=0;
  while abs(aa-bb)>1 do
    begin
       cc:=(aa+bb) shr 1;
       if z[cc]<gr then aa:=cc else bb:=cc;

    end;
  { writeln(' cc= ',cc);
  } cc:=min(cc+3,pp+1);
   repeat dec(cc) until z[cc]<=gr;
   if gr=0 then cc:=0;
   ot:=cc;
  ff:=ot;
end;

function fff(gr:int64):int64;
var ot,aa,bb,cc:int64;
begin
  aa:=1; bb:=ttt;  cc:=aa; ot:=0;
  while abs(aa-bb)>1 do
    begin
       cc:=(aa+bb) shr 1;
       if zz[cc]<gr then aa:=cc else bb:=cc;

    end;
  { writeln(' cc= ',cc);
  } cc:=min(cc+3,pp+1);
   repeat dec(cc) until zz[cc]<=gr;
   if gr=0 then cc:=0;
   ot:=cc;
  fff:=ot;
end;

begin
 {  assign(input,'input.txt');reset(input);
   assign(output,'output.txt');rewrite(output);
  }

    read(p);
    for i:=1 to p do read(x[i],y[i]);
    for i:=1 to p do a[i]:=2000000000*max(x[i],y[i])+x[i];
    for i:=1 to p do a1[i]:=i;

   {   for i:=1 to p do writeln(a[i],' ',a1[i]);
    }

   n:=1; repeat n:=n*2 until n>=p;
   for i:=p+1 to n do a[i]:=besk;
   sort(a);
  { for i:=1 to p do writeln(a[i],' ',a1[i]);
  } for i:=1 to p do b[a1[i]]:=i;
   for i:=1 to p do
     begin xx[i]:=x[a1[i]]; yy[i]:=y[a1[i]];   end;

   {  for i:=1 to p do writeln(xx[i],' ',yy[i]);
    }
     for i:=1 to p do if max(xx[i],yy[i])>max(xx[i-1],yy[i-1]) then
       begin inc(q); z[q]:=i;  end;
       inc(q); z[q]:=p+1;
     {  for i:=1 to q do write(z[i],' ');
       writeln;
      }
        for i:=1 to q do
          begin
       {     writeln('lavel= ',i);
            for j:=z[i-1] to z[i]-1 do  writeln('j= ',j,' point  ',xx[j],' ',yy[j]);
        }

          end;

       for i:=2 to p do begin ddleft[i]:=besk; ddright[i]:=besk; end;

      for j:=2 to q do
    begin
       p1:=z[j-1]; p2:=z[j]-1;
       p3:=z[j-2]; p4:=z[j-1]-1;

       len:= abs(xx[p1]-xx[p2])+abs(yy[p1]-yy[p2]);
       t14:=abs(xx[p1]-xx[p4])+abs(yy[p1]-yy[p4]);
       t13:=abs(xx[p1]-xx[p3])+abs(yy[p1]-yy[p3]);

       t24:=abs(xx[p2]-xx[p4])+abs(yy[p2]-yy[p4]);
       t23:=abs(xx[p2]-xx[p3])+abs(yy[p2]-yy[p3]);

    {   writeln(len,' t14= ',t14,' t13= ',t13,' t24= ',t24,' t23= ',t23);
     }

       ddleft[j]:=min(ddleft[j],len+ddleft[j-1]+t23);
       ddleft[j]:=min(ddleft[j],len+ddright[j-1]+t24);

       ddright[j]:=min(ddright[j],len+ddleft[j-1]+t13);
       ddright[j]:=min(ddright[j],len+ddright[j-1]+t14);

  {    writeln('j= ',j,' ', ddleft[j],' ',ddright[j]);
   }
    end;

     writeln(min(ddleft[q],ddright[q]));

 1: close (output);
end.

                    const eps=1e-10;
                    besk=8000000000000000000;
                     label 1,2,33,44;
                 type
                     mas=array[-200000..2*1100000+1] of int64;
                  point=record x,y:int64 end;
                  point1=^point;
                  otr=record st,fin:point end;
var mask,kol1,stepp,mm,lavel,l,kol,dl,i1,j1,imin,step,i,j,k,m,n1,k1,w,mesto,pl1,pl2,pl3:longint;
len,t14,t24,t23,t13,p2,p3,p4,ttt,p1,ii,jj,kk,sum,pos1,pos2,tt,ans1,ans2,t,pp,ans,qq,ott,n,cc,nn,modul,p,ot,pmin,tmax,minf,gr1,gr2,tt1,nnn,d,raz1,raz2,v,s,st,q,gr:int64; flag1:boolean;
 zan:array[0..1000000] of boolean;
 cha:char;
z,b1,a1:array[-10..3000000] of int64;
ddleft,ddright:array[-100000..500000] of int64;
dd:array [-1..3000,-1..3000] of int64;
bbbb,cccc:array[0..100000] of extended;
 ss,ss1:string;
t1,t2,t3:extended;
xx,yy,x1,y1,x,y,mnog,stepen:array[-1000000..1000000] of int64;
left,right,zz,ll,rr,aa,ppp, c,a,b:mas; flag:boolean;  pl:longint;
function srav(i,j:longint):boolean;
begin if (a[i]<a[j]){or((a[i]=a[j])and(a1[i]<a1[j]))} then srav:=true else srav:=false;  end;
procedure sl (k,l,m:longint);  {k- dlina, l,m - nachalo dvuh blokov}
begin
i:=l;j:=m; flag:=true; step:=0;while flag do begin
if srav(i,j) then begin begin b[l+step]:=a[i];b1[l+step]:=a1[i];end;
inc(step);inc(i);
{writeln('step=',step,' i=',i);} end;
if not srav(i,j) then begin begin b[l+step]:=a[j];b1[l+step]:=a1[j];end;
inc(step);inc(j);end;
if  ((i>=l+k) or (j>=m+k)) then flag:=false;
end;
if(i>=l+k) then repeat b[l+step]:=a[j];b1[l+step]:=a1[j];inc(step);inc(j);until (j>=m+k);
if(j>=m+k) then repeat b[l+step]:=a[i];b1[l+step]:=a1[i];inc(step);inc(i);until (i>=l+k);
end;
procedure sort(var c:mas);

begin

k:=1; repeat
l:=1;m:=k+l; repeat sl(k,l,m); l:=l+2*k;m:=m+2*k; until (l>=n); k:=k*2;
for i:=1 to n do begin a[i]:=b[i];a1[i]:=b1[i]; end;
until (k>=n);
end;

 function  max(a,b:int64):int64;
 begin max:=a; if b>a then max:=b; end;
  function  min(a,b:int64):int64;
 begin min:=a; if b<a then min:=b; end;
function gcd(a,b:int64):int64; var p,t:int64;
begin if (a>0)and(b>0) then
   begin while (b>0) do begin t:=a mod b;a:=b;b:=t;    end;
    p:=a;
   end else if a=0 then p:=b else p:=a;
gcd:=p;
end;

function ff(gr:int64):int64;
var ot,aa,bb,cc:int64;
begin
  aa:=1; bb:=tt;  cc:=aa; ot:=0;
  while abs(aa-bb)>1 do
    begin
       cc:=(aa+bb) shr 1;
       if z[cc]<gr then aa:=cc else bb:=cc;

    end;
  { writeln(' cc= ',cc);
  } cc:=min(cc+3,pp+1);
   repeat dec(cc) until z[cc]<=gr;
   if gr=0 then cc:=0;
   ot:=cc;
  ff:=ot;
end;

function fff(gr:int64):int64;
var ot,aa,bb,cc:int64;
begin
  aa:=1; bb:=ttt;  cc:=aa; ot:=0;
  while abs(aa-bb)>1 do
    begin
       cc:=(aa+bb) shr 1;
       if zz[cc]<gr then aa:=cc else bb:=cc;

    end;
  { writeln(' cc= ',cc);
  } cc:=min(cc+3,pp+1);
   repeat dec(cc) until zz[cc]<=gr;
   if gr=0 then cc:=0;
   ot:=cc;
  fff:=ot;
end;

begin
  { assign(input,'input.txt');reset(input);
   assign(output,'output.txt');rewrite(output);
   }

    read(p);
    for i:=1 to p do read(x[i],y[i]);
    p:=10;
    for i:=1 to p do if odd(i) then begin x[i]:=1000000-i; y[i]:=0;  end
    else begin y[i]:=1000000-i; x[i]:=0;  end;

    if p=1 then begin writeln(x[1]+y[1]); goto 1;  end;

    for i:=1 to p do a[i]:=3000000000*max(x[i],y[i])+2*x[i]-y[i];
    for i:=1 to p do a1[i]:=i;

   {   for i:=1 to p do writeln(a[i],' ',a1[i]);
    }

   n:=1; repeat n:=n*2 until n>=p;
   for i:=p+1 to n do a[i]:=besk;
   sort(a);
  { for i:=1 to p do writeln(a[i],' ',a1[i]);
  } for i:=1 to p do b[a1[i]]:=i;
   for i:=1 to p do
     begin xx[i]:=x[a1[i]]; yy[i]:=y[a1[i]];   end;

   {  for i:=1 to p do writeln(xx[i],' ',yy[i]);
    }
     for i:=1 to p do if max(xx[i],yy[i])>max(xx[i-1],yy[i-1]) then
       begin inc(q); z[q]:=i;  end;
       inc(q); z[q]:=p+1;
     {  for i:=1 to q do write(z[i],' ');
       writeln;
      }
        for i:=1 to q do
          begin
         {   writeln('lavel= ',i);
            for j:=z[i-1] to z[i]-1 do  writeln('j= ',j,' point  ',xx[j],' ',yy[j]);
          }

          end;

       for i:=2 to p do begin ddleft[i]:=besk; ddright[i]:=besk; end;

      for j:=2 to q do
    begin
       p1:=z[j-1]; p2:=z[j]-1;
       p3:=z[j-2]; p4:=z[j-1]-1;

       len:= abs(xx[p1]-xx[p2])+abs(yy[p1]-yy[p2]);
       t14:=abs(xx[p1]-xx[p4])+abs(yy[p1]-yy[p4]);
       t13:=abs(xx[p1]-xx[p3])+abs(yy[p1]-yy[p3]);

       t24:=abs(xx[p2]-xx[p4])+abs(yy[p2]-yy[p4]);
       t23:=abs(xx[p2]-xx[p3])+abs(yy[p2]-yy[p3]);

     {  writeln(len,' t14= ',t14,' t13= ',t13,' t24= ',t24,' t23= ',t23);
      }

       ddleft[j]:=min(ddleft[j],len+ddleft[j-1]+t23);
       ddleft[j]:=min(ddleft[j],len+ddright[j-1]+t24);

       ddright[j]:=min(ddright[j],len+ddleft[j-1]+t13);
       ddright[j]:=min(ddright[j],len+ddright[j-1]+t14);

    {  writeln('j= ',j,' ', ddleft[j],' ',ddright[j]);
     }
    end;

     writeln(min(max(ddleft[q],ddleft[q-1]),max(ddright[q],ddright[q-1])));

 1: close (output);
end.

                    const eps=1e-10;
                    besk=8000000000000000000;
                     label 1,2,33,44;
                 type
                     mas=array[-200000..2*1100000+1] of int64;
                  point=record x,y:int64 end;
                  point1=^point;
                  otr=record st,fin:point end;
var mask,kol1,stepp,mm,lavel,l,kol,dl,i1,j1,imin,step,i,j,k,m,n1,k1,w,mesto,pl1,pl2,pl3:longint;
len,t14,t24,t23,t13,p2,p3,p4,ttt,p1,ii,jj,kk,sum,pos1,pos2,tt,ans1,ans2,t,pp,ans,qq,ott,n,cc,nn,modul,p,ot,pmin,tmax,minf,gr1,gr2,tt1,nnn,d,raz1,raz2,v,s,st,q,gr:int64; flag1:boolean;
 zan:array[0..1000000] of boolean;
 cha:char;
z,b1,a1:array[-10..3000000] of int64;
ddleft,ddright:array[-100000..500000] of int64;
dd:array [-1..3000,-1..3000] of int64;
bbbb,cccc:array[0..100000] of extended;
 ss,ss1:string;
t1,t2,t3:extended;
xx,yy,x1,y1,x,y,mnog,stepen:array[-1000000..1000000] of int64;
left,right,zz,ll,rr,aa,ppp, c,a,b:mas; flag:boolean;  pl:longint;
function srav(i,j:longint):boolean;
begin if (a[i]<a[j]){or((a[i]=a[j])and(a1[i]<a1[j]))} then srav:=true else srav:=false;  end;
procedure sl (k,l,m:longint);  {k- dlina, l,m - nachalo dvuh blokov}
begin
i:=l;j:=m; flag:=true; step:=0;while flag do begin
if srav(i,j) then begin begin b[l+step]:=a[i];b1[l+step]:=a1[i];end;
inc(step);inc(i);
{writeln('step=',step,' i=',i);} end;
if not srav(i,j) then begin begin b[l+step]:=a[j];b1[l+step]:=a1[j];end;
inc(step);inc(j);end;
if  ((i>=l+k) or (j>=m+k)) then flag:=false;
end;
if(i>=l+k) then repeat b[l+step]:=a[j];b1[l+step]:=a1[j];inc(step);inc(j);until (j>=m+k);
if(j>=m+k) then repeat b[l+step]:=a[i];b1[l+step]:=a1[i];inc(step);inc(i);until (i>=l+k);
end;
procedure sort(var c:mas);

begin

k:=1; repeat
l:=1;m:=k+l; repeat sl(k,l,m); l:=l+2*k;m:=m+2*k; until (l>=n); k:=k*2;
for i:=1 to n do begin a[i]:=b[i];a1[i]:=b1[i]; end;
until (k>=n);
end;

 function  max(a,b:int64):int64;
 begin max:=a; if b>a then max:=b; end;
  function  min(a,b:int64):int64;
 begin min:=a; if b<a then min:=b; end;
function gcd(a,b:int64):int64; var p,t:int64;
begin if (a>0)and(b>0) then
   begin while (b>0) do begin t:=a mod b;a:=b;b:=t;    end;
    p:=a;
   end else if a=0 then p:=b else p:=a;
gcd:=p;
end;

function ff(gr:int64):int64;
var ot,aa,bb,cc:int64;
begin
  aa:=1; bb:=tt;  cc:=aa; ot:=0;
  while abs(aa-bb)>1 do
    begin
       cc:=(aa+bb) shr 1;
       if z[cc]<gr then aa:=cc else bb:=cc;

    end;
  { writeln(' cc= ',cc);
  } cc:=min(cc+3,pp+1);
   repeat dec(cc) until z[cc]<=gr;
   if gr=0 then cc:=0;
   ot:=cc;
  ff:=ot;
end;

function fff(gr:int64):int64;
var ot,aa,bb,cc:int64;
begin
  aa:=1; bb:=ttt;  cc:=aa; ot:=0;
  while abs(aa-bb)>1 do
    begin
       cc:=(aa+bb) shr 1;
       if zz[cc]<gr then aa:=cc else bb:=cc;

    end;
  { writeln(' cc= ',cc);
  } cc:=min(cc+3,pp+1);
   repeat dec(cc) until zz[cc]<=gr;
   if gr=0 then cc:=0;
   ot:=cc;
  fff:=ot;
end;

begin
 {  assign(input,'input.txt');reset(input);
   assign(output,'output.txt');rewrite(output);
  }

    read(p);
    for i:=1 to p do read(x[i],y[i]);
    if p=1 then begin writeln(x[1]+y[1]); goto 1;  end;

    for i:=1 to p do a[i]:=3000000000*max(x[i],y[i])+2*x[i]-y[i];
    for i:=1 to p do a1[i]:=i;

   {   for i:=1 to p do writeln(a[i],' ',a1[i]);
    }

   n:=1; repeat n:=n*2 until n>=p;
   for i:=p+1 to n do a[i]:=besk;
   sort(a);
  { for i:=1 to p do writeln(a[i],' ',a1[i]);
  } for i:=1 to p do b[a1[i]]:=i;
   for i:=1 to p do
     begin xx[i]:=x[a1[i]]; yy[i]:=y[a1[i]];   end;

   {  for i:=1 to p do writeln(xx[i],' ',yy[i]);
    }
     for i:=1 to p do if max(xx[i],yy[i])>max(xx[i-1],yy[i-1]) then
       begin inc(q); z[q]:=i;  end;
       inc(q); z[q]:=p+1;
     {  for i:=1 to q do write(z[i],' ');
       writeln;
      }
        for i:=1 to q do
          begin
       {     writeln('lavel= ',i);
            for j:=z[i-1] to z[i]-1 do  writeln('j= ',j,' point  ',xx[j],' ',yy[j]);
        }

          end;

       for i:=2 to p do begin ddleft[i]:=besk; ddright[i]:=besk; end;

      for j:=2 to q do
    begin
       p1:=z[j-1]; p2:=z[j]-1;
       p3:=z[j-2]; p4:=z[j-1]-1;

       len:= abs(xx[p1]-xx[p2])+abs(yy[p1]-yy[p2]);
       t14:=abs(xx[p1]-xx[p4])+abs(yy[p1]-yy[p4]);
       t13:=abs(xx[p1]-xx[p3])+abs(yy[p1]-yy[p3]);

       t24:=abs(xx[p2]-xx[p4])+abs(yy[p2]-yy[p4]);
       t23:=abs(xx[p2]-xx[p3])+abs(yy[p2]-yy[p3]);

    {   writeln(len,' t14= ',t14,' t13= ',t13,' t24= ',t24,' t23= ',t23);
     }

       ddleft[j]:=min(ddleft[j],len+ddleft[j-1]+t23);
       ddleft[j]:=min(ddleft[j],len+ddright[j-1]+t24);

       ddright[j]:=min(ddright[j],len+ddleft[j-1]+t13);
       ddright[j]:=min(ddright[j],len+ddright[j-1]+t14);

  {    writeln('j= ',j,' ', ddleft[j],' ',ddright[j]);
   }
    end;

     writeln(min(ddleft[q],ddright[q]));

 1: close (output);
end.

                    const eps=1e-10;
                    besk=8000000000000000000;
                     label 1,2,33,44;
                 type
                     mas=array[-200000..2*1100000+1] of int64;
                  point=record x,y:int64 end;
                  point1=^point;
                  otr=record st,fin:point end;
var mask,kol1,stepp,mm,lavel,l,kol,dl,i1,j1,imin,step,i,j,k,m,n1,k1,w,mesto,pl1,pl2,pl3:longint;
len,t14,t24,t23,t13,p2,p3,p4,ttt,p1,ii,jj,kk,sum,pos1,pos2,tt,ans1,ans2,t,pp,ans,qq,ott,n,cc,nn,modul,p,ot,pmin,tmax,minf,gr1,gr2,tt1,nnn,d,raz1,raz2,v,s,st,q,gr:int64; flag1:boolean;
 zan:array[0..1000000] of boolean;
 cha:char;
z,b1,a1:array[-10..3000000] of int64;
ddleft,ddright:array[-100000..500000] of int64;
dd:array [-1..3000,-1..3000] of int64;
bbbb,cccc:array[0..100000] of extended;
 ss,ss1:string;
t1,t2,t3:extended;
xx,yy,x1,y1,x,y,mnog,stepen:array[-1000000..1000000] of int64;
left,right,zz,ll,rr,aa,ppp, c,a,b:mas; flag:boolean;  pl:longint;
function srav(i,j:longint):boolean;
begin if (a[i]<a[j]){or((a[i]=a[j])and(a1[i]<a1[j]))} then srav:=true else srav:=false;  end;
procedure sl (k,l,m:longint);  {k- dlina, l,m - nachalo dvuh blokov}
begin
i:=l;j:=m; flag:=true; step:=0;while flag do begin
if srav(i,j) then begin begin b[l+step]:=a[i];b1[l+step]:=a1[i];end;
inc(step);inc(i);
{writeln('step=',step,' i=',i);} end;
if not srav(i,j) then begin begin b[l+step]:=a[j];b1[l+step]:=a1[j];end;
inc(step);inc(j);end;
if  ((i>=l+k) or (j>=m+k)) then flag:=false;
end;
if(i>=l+k) then repeat b[l+step]:=a[j];b1[l+step]:=a1[j];inc(step);inc(j);until (j>=m+k);
if(j>=m+k) then repeat b[l+step]:=a[i];b1[l+step]:=a1[i];inc(step);inc(i);until (i>=l+k);
end;
procedure sort(var c:mas);

begin

k:=1; repeat
l:=1;m:=k+l; repeat sl(k,l,m); l:=l+2*k;m:=m+2*k; until (l>=n); k:=k*2;
for i:=1 to n do begin a[i]:=b[i];a1[i]:=b1[i]; end;
until (k>=n);
end;

 function  max(a,b:int64):int64;
 begin max:=a; if b>a then max:=b; end;
  function  min(a,b:int64):int64;
 begin min:=a; if b<a then min:=b; end;
function gcd(a,b:int64):int64; var p,t:int64;
begin if (a>0)and(b>0) then
   begin while (b>0) do begin t:=a mod b;a:=b;b:=t;    end;
    p:=a;
   end else if a=0 then p:=b else p:=a;
gcd:=p;
end;

function ff(gr:int64):int64;
var ot,aa,bb,cc:int64;
begin
  aa:=1; bb:=tt;  cc:=aa; ot:=0;
  while abs(aa-bb)>1 do
    begin
       cc:=(aa+bb) shr 1;
       if z[cc]<gr then aa:=cc else bb:=cc;

    end;
  { writeln(' cc= ',cc);
  } cc:=min(cc+3,pp+1);
   repeat dec(cc) until z[cc]<=gr;
   if gr=0 then cc:=0;
   ot:=cc;
  ff:=ot;
end;

function fff(gr:int64):int64;
var ot,aa,bb,cc:int64;
begin
  aa:=1; bb:=ttt;  cc:=aa; ot:=0;
  while abs(aa-bb)>1 do
    begin
       cc:=(aa+bb) shr 1;
       if zz[cc]<gr then aa:=cc else bb:=cc;

    end;
  { writeln(' cc= ',cc);
  } cc:=min(cc+3,pp+1);
   repeat dec(cc) until zz[cc]<=gr;
   if gr=0 then cc:=0;
   ot:=cc;
  fff:=ot;
end;

begin
  { assign(input,'input.txt');reset(input);
   assign(output,'output.txt');rewrite(output);
   }

    read(p);
    for i:=1 to p do read(x[i],y[i]);
    p:=10;
    for i:=1 to p do if odd(i) then begin x[i]:=1000000-i; y[i]:=0;  end
    else begin y[i]:=1000000-i; x[i]:=0;  end;

    if p=1 then begin writeln(x[1]+y[1]); goto 1;  end;

    for i:=1 to p do a[i]:=3000000000*max(x[i],y[i])+2*x[i]-y[i];
    for i:=1 to p do a1[i]:=i;

   {   for i:=1 to p do writeln(a[i],' ',a1[i]);
    }

   n:=1; repeat n:=n*2 until n>=p;
   for i:=p+1 to n do a[i]:=besk;
   sort(a);
  { for i:=1 to p do writeln(a[i],' ',a1[i]);
  } for i:=1 to p do b[a1[i]]:=i;
   for i:=1 to p do
     begin xx[i]:=x[a1[i]]; yy[i]:=y[a1[i]];   end;

   {  for i:=1 to p do writeln(xx[i],' ',yy[i]);
    }
     for i:=1 to p do if max(xx[i],yy[i])>max(xx[i-1],yy[i-1]) then
       begin inc(q); z[q]:=i;  end;
       inc(q); z[q]:=p+1;
     {  for i:=1 to q do write(z[i],' ');
       writeln;
      }
        for i:=1 to q do
          begin
        {    writeln('lavel= ',i);
            for j:=z[i-1] to z[i]-1 do  writeln('j= ',j,' point  ',xx[j],' ',yy[j]);
         }

          end;

       for i:=2 to p+1 do begin ddleft[i]:=besk; ddright[i]:=besk; end;

      for j:=2 to q do
    begin
       p1:=z[j-1]; p2:=z[j]-1;
       p3:=z[j-2]; p4:=z[j-1]-1;

      { writeln('step= ',j);
       }
       len:= abs(xx[p1]-xx[p2])+abs(yy[p1]-yy[p2]);
       t14:=abs(xx[p1]-xx[p4])+abs(yy[p1]-yy[p4]);
       t13:=abs(xx[p1]-xx[p3])+abs(yy[p1]-yy[p3]);

       t24:=abs(xx[p2]-xx[p4])+abs(yy[p2]-yy[p4]);
       t23:=abs(xx[p2]-xx[p3])+abs(yy[p2]-yy[p3]);

      { writeln(len,' t14= ',t14,' t13= ',t13,' t24= ',t24,' t23= ',t23);
        writeln;
       }

       ddleft[j]:=min(ddleft[j],len+ddleft[j-1]+t23);
       ddleft[j]:=min(ddleft[j],len+ddright[j-1]+t24);

       ddright[j]:=min(ddright[j],len+ddleft[j-1]+t13);
       ddright[j]:=min(ddright[j],len+ddright[j-1]+t14);

     { writeln('j= ',j,' ', ddleft[j],' ',ddright[j]);
      }
    end;

     writeln(min(ddleft[q],ddright[q]));

 1: close (output);
end.

                    const eps=1e-10;
                    besk=8000000000000000000;
                     label 1,2,33,44;
                 type
                     mas=array[-200000..2*1100000+1] of int64;
                  point=record x,y:int64 end;
                  point1=^point;
                  otr=record st,fin:point end;
var mask,kol1,stepp,mm,lavel,l,kol,dl,i1,j1,imin,step,i,j,k,m,n1,k1,w,mesto,pl1,pl2,pl3:longint;
len,t14,t24,t23,t13,p2,p3,p4,ttt,p1,ii,jj,kk,sum,pos1,pos2,tt,ans1,ans2,t,pp,ans,qq,ott,n,cc,nn,modul,p,ot,pmin,tmax,minf,gr1,gr2,tt1,nnn,d,raz1,raz2,v,s,st,q,gr:int64; flag1:boolean;
 zan:array[0..1000000] of boolean;
 cha:char;
z,b1,a1:array[-10..3000000] of int64;
ddleft,ddright:array[-100000..500000] of int64;
dd:array [-1..3000,-1..3000] of int64;
bbbb,cccc:array[0..100000] of extended;
 ss,ss1:string;
t1,t2,t3:extended;
xx,yy,x1,y1,x,y,mnog,stepen:array[-1000000..1000000] of int64;
left,right,zz,ll,rr,aa,ppp, c,a,b:mas; flag:boolean;  pl:longint;
function srav(i,j:longint):boolean;
begin if (a[i]<a[j]){or((a[i]=a[j])and(a1[i]<a1[j]))} then srav:=true else srav:=false;  end;
procedure sl (k,l,m:longint);  {k- dlina, l,m - nachalo dvuh blokov}
begin
i:=l;j:=m; flag:=true; step:=0;while flag do begin
if srav(i,j) then begin begin b[l+step]:=a[i];b1[l+step]:=a1[i];end;
inc(step);inc(i);
{writeln('step=',step,' i=',i);} end;
if not srav(i,j) then begin begin b[l+step]:=a[j];b1[l+step]:=a1[j];end;
inc(step);inc(j);end;
if  ((i>=l+k) or (j>=m+k)) then flag:=false;
end;
if(i>=l+k) then repeat b[l+step]:=a[j];b1[l+step]:=a1[j];inc(step);inc(j);until (j>=m+k);
if(j>=m+k) then repeat b[l+step]:=a[i];b1[l+step]:=a1[i];inc(step);inc(i);until (i>=l+k);
end;
procedure sort(var c:mas);

begin

k:=1; repeat
l:=1;m:=k+l; repeat sl(k,l,m); l:=l+2*k;m:=m+2*k; until (l>=n); k:=k*2;
for i:=1 to n do begin a[i]:=b[i];a1[i]:=b1[i]; end;
until (k>=n);
end;

 function  max(a,b:int64):int64;
 begin max:=a; if b>a then max:=b; end;
  function  min(a,b:int64):int64;
 begin min:=a; if b<a then min:=b; end;
function gcd(a,b:int64):int64; var p,t:int64;
begin if (a>0)and(b>0) then
   begin while (b>0) do begin t:=a mod b;a:=b;b:=t;    end;
    p:=a;
   end else if a=0 then p:=b else p:=a;
gcd:=p;
end;

function ff(gr:int64):int64;
var ot,aa,bb,cc:int64;
begin
  aa:=1; bb:=tt;  cc:=aa; ot:=0;
  while abs(aa-bb)>1 do
    begin
       cc:=(aa+bb) shr 1;
       if z[cc]<gr then aa:=cc else bb:=cc;

    end;
  { writeln(' cc= ',cc);
  } cc:=min(cc+3,pp+1);
   repeat dec(cc) until z[cc]<=gr;
   if gr=0 then cc:=0;
   ot:=cc;
  ff:=ot;
end;

function fff(gr:int64):int64;
var ot,aa,bb,cc:int64;
begin
  aa:=1; bb:=ttt;  cc:=aa; ot:=0;
  while abs(aa-bb)>1 do
    begin
       cc:=(aa+bb) shr 1;
       if zz[cc]<gr then aa:=cc else bb:=cc;

    end;
  { writeln(' cc= ',cc);
  } cc:=min(cc+3,pp+1);
   repeat dec(cc) until zz[cc]<=gr;
   if gr=0 then cc:=0;
   ot:=cc;
  fff:=ot;
end;

begin
  { assign(input,'input.txt');reset(input);
   assign(output,'output.txt');rewrite(output);
   }

    read(p);
    for i:=1 to p do read(x[i],y[i]);
   { p:=10;
    for i:=1 to p do if odd(i) then begin x[i]:=1000000-i; y[i]:=0;  end
    else begin y[i]:=1000000-i; x[i]:=0;  end;
    }

    if p=1 then begin writeln(x[1]+y[1]); goto 1;  end;

    for i:=1 to p do a[i]:=3000000000*max(x[i],y[i])+2*x[i]-y[i];
    for i:=1 to p do a1[i]:=i;

   {   for i:=1 to p do writeln(a[i],' ',a1[i]);
    }

   n:=1; repeat n:=n*2 until n>=p;
   for i:=p+1 to n do a[i]:=besk;
   sort(a);
  { for i:=1 to p do writeln(a[i],' ',a1[i]);
  } for i:=1 to p do b[a1[i]]:=i;
   for i:=1 to p do
     begin xx[i]:=x[a1[i]]; yy[i]:=y[a1[i]];   end;

   {  for i:=1 to p do writeln(xx[i],' ',yy[i]);
    }
     for i:=1 to p do if max(xx[i],yy[i])>max(xx[i-1],yy[i-1]) then
       begin inc(q); z[q]:=i;  end;
       inc(q); z[q]:=p+1;
     {  for i:=1 to q do write(z[i],' ');
       writeln;
      }
        for i:=1 to q do
          begin
         {   writeln('lavel= ',i);
            for j:=z[i-1] to z[i]-1 do  writeln('j= ',j,' point  ',xx[j],' ',yy[j]);
          }

          end;

       for i:=2 to p do begin ddleft[i]:=besk; ddright[i]:=besk; end;

      for j:=2 to q do
    begin
       p1:=z[j-1]; p2:=z[j]-1;
       p3:=z[j-2]; p4:=z[j-1]-1;

       len:= abs(xx[p1]-xx[p2])+abs(yy[p1]-yy[p2]);
       t14:=abs(xx[p1]-xx[p4])+abs(yy[p1]-yy[p4]);
       t13:=abs(xx[p1]-xx[p3])+abs(yy[p1]-yy[p3]);

       t24:=abs(xx[p2]-xx[p4])+abs(yy[p2]-yy[p4]);
       t23:=abs(xx[p2]-xx[p3])+abs(yy[p2]-yy[p3]);

     {  writeln(len,' t14= ',t14,' t13= ',t13,' t24= ',t24,' t23= ',t23);
      }

       ddleft[j]:=min(ddleft[j],len+ddleft[j-1]+t23);
       ddleft[j]:=min(ddleft[j],len+ddright[j-1]+t24);

       ddright[j]:=min(ddright[j],len+ddleft[j-1]+t13);
       ddright[j]:=min(ddright[j],len+ddright[j-1]+t14);

    {  writeln('j= ',j,' ', ddleft[j],' ',ddright[j]);
     }
    end;

     writeln(min(max(ddleft[q],ddleft[q-1]),max(ddright[q],ddright[q-1])));

 1: close (output);
end.

                    const eps=1e-10;
                    besk=8000000000000000000;
                     label 1,2,33,44;
                 type
                     mas=array[-200000..2*1100000+1] of int64;
                  point=record x,y:int64 end;
                  point1=^point;
                  otr=record st,fin:point end;
var mask,kol1,stepp,mm,lavel,l,kol,dl,i1,j1,imin,step,i,j,k,m,n1,k1,w,mesto,pl1,pl2,pl3:longint;
len,t14,t24,t23,t13,p2,p3,p4,ttt,p1,ii,jj,kk,sum,pos1,pos2,tt,ans1,ans2,t,pp,ans,qq,ott,n,cc,nn,modul,p,ot,pmin,tmax,minf,gr1,gr2,tt1,nnn,d,raz1,raz2,v,s,st,q,gr:int64; flag1:boolean;
 zan:array[0..1000000] of boolean;
 cha:char;
z,b1,a1:array[-10..3000000] of int64;
ddleft,ddright:array[-100000..500000] of int64;
dd:array [-1..3000,-1..3000] of int64;
bbbb,cccc:array[0..100000] of extended;
 ss,ss1:string;
t1,t2,t3:extended;
xx,yy,x1,y1,x,y,mnog,stepen:array[-1000000..1000000] of int64;
left,right,zz,ll,rr,aa,ppp, c,a,b:mas; flag:boolean;  pl:longint;
function srav(i,j:longint):boolean;
begin if (a[i]<a[j]){or((a[i]=a[j])and(a1[i]<a1[j]))} then srav:=true else srav:=false;  end;
procedure sl (k,l,m:longint);  {k- dlina, l,m - nachalo dvuh blokov}
begin
i:=l;j:=m; flag:=true; step:=0;while flag do begin
if srav(i,j) then begin begin b[l+step]:=a[i];b1[l+step]:=a1[i];end;
inc(step);inc(i);
{writeln('step=',step,' i=',i);} end;
if not srav(i,j) then begin begin b[l+step]:=a[j];b1[l+step]:=a1[j];end;
inc(step);inc(j);end;
if  ((i>=l+k) or (j>=m+k)) then flag:=false;
end;
if(i>=l+k) then repeat b[l+step]:=a[j];b1[l+step]:=a1[j];inc(step);inc(j);until (j>=m+k);
if(j>=m+k) then repeat b[l+step]:=a[i];b1[l+step]:=a1[i];inc(step);inc(i);until (i>=l+k);
end;
procedure sort(var c:mas);

begin

k:=1; repeat
l:=1;m:=k+l; repeat sl(k,l,m); l:=l+2*k;m:=m+2*k; until (l>=n); k:=k*2;
for i:=1 to n do begin a[i]:=b[i];a1[i]:=b1[i]; end;
until (k>=n);
end;

 function  max(a,b:int64):int64;
 begin max:=a; if b>a then max:=b; end;
  function  min(a,b:int64):int64;
 begin min:=a; if b<a then min:=b; end;
function gcd(a,b:int64):int64; var p,t:int64;
begin if (a>0)and(b>0) then
   begin while (b>0) do begin t:=a mod b;a:=b;b:=t;    end;
    p:=a;
   end else if a=0 then p:=b else p:=a;
gcd:=p;
end;

function ff(gr:int64):int64;
var ot,aa,bb,cc:int64;
begin
  aa:=1; bb:=tt;  cc:=aa; ot:=0;
  while abs(aa-bb)>1 do
    begin
       cc:=(aa+bb) shr 1;
       if z[cc]<gr then aa:=cc else bb:=cc;

    end;
  { writeln(' cc= ',cc);
  } cc:=min(cc+3,pp+1);
   repeat dec(cc) until z[cc]<=gr;
   if gr=0 then cc:=0;
   ot:=cc;
  ff:=ot;
end;

function fff(gr:int64):int64;
var ot,aa,bb,cc:int64;
begin
  aa:=1; bb:=ttt;  cc:=aa; ot:=0;
  while abs(aa-bb)>1 do
    begin
       cc:=(aa+bb) shr 1;
       if zz[cc]<gr then aa:=cc else bb:=cc;

    end;
  { writeln(' cc= ',cc);
  } cc:=min(cc+3,pp+1);
   repeat dec(cc) until zz[cc]<=gr;
   if gr=0 then cc:=0;
   ot:=cc;
  fff:=ot;
end;

begin
 {  assign(input,'input.txt');reset(input);
   assign(output,'output.txt');rewrite(output);
  }

    read(p);
    for i:=1 to p do read(x[i],y[i]);
    if p=1 then begin writeln(x[1]+y[1]); goto 1;  end;

    for i:=1 to p do a[i]:=2000000000*max(x[i],y[i])+x[i];
    for i:=1 to p do a1[i]:=i;

   {   for i:=1 to p do writeln(a[i],' ',a1[i]);
    }

   n:=1; repeat n:=n*2 until n>=p;
   for i:=p+1 to n do a[i]:=besk;
   sort(a);
  { for i:=1 to p do writeln(a[i],' ',a1[i]);
  } for i:=1 to p do b[a1[i]]:=i;
   for i:=1 to p do
     begin xx[i]:=x[a1[i]]; yy[i]:=y[a1[i]];   end;

   {  for i:=1 to p do writeln(xx[i],' ',yy[i]);
    }
     for i:=1 to p do if max(xx[i],yy[i])>max(xx[i-1],yy[i-1]) then
       begin inc(q); z[q]:=i;  end;
       inc(q); z[q]:=p+1;
     {  for i:=1 to q do write(z[i],' ');
       writeln;
      }
        for i:=1 to q do
          begin
       {     writeln('lavel= ',i);
            for j:=z[i-1] to z[i]-1 do  writeln('j= ',j,' point  ',xx[j],' ',yy[j]);
        }

          end;

       for i:=2 to p do begin ddleft[i]:=besk; ddright[i]:=besk; end;

      for j:=2 to q do
    begin
       p1:=z[j-1]; p2:=z[j]-1;
       p3:=z[j-2]; p4:=z[j-1]-1;

       len:= abs(xx[p1]-xx[p2])+abs(yy[p1]-yy[p2]);
       t14:=abs(xx[p1]-xx[p4])+abs(yy[p1]-yy[p4]);
       t13:=abs(xx[p1]-xx[p3])+abs(yy[p1]-yy[p3]);

       t24:=abs(xx[p2]-xx[p4])+abs(yy[p2]-yy[p4]);
       t23:=abs(xx[p2]-xx[p3])+abs(yy[p2]-yy[p3]);

    {   writeln(len,' t14= ',t14,' t13= ',t13,' t24= ',t24,' t23= ',t23);
     }

       ddleft[j]:=min(ddleft[j],len+ddleft[j-1]+t23);
       ddleft[j]:=min(ddleft[j],len+ddright[j-1]+t24);

       ddright[j]:=min(ddright[j],len+ddleft[j-1]+t13);
       ddright[j]:=min(ddright[j],len+ddright[j-1]+t14);

  {    writeln('j= ',j,' ', ddleft[j],' ',ddright[j]);
   }
    end;

     writeln(min(ddleft[q],ddright[q]));

 1: close (output);
end.

program ProjectF;

uses
  Math;

type
  TLvl = record
    l, r, len: longint;
    d: array[1..4] of longint;
  end;

var
  n, i, LvlCount: longint;
  x, y, l, r: array[0..200000] of longint;
  Lvl: array[0..200000] of Tlvl;

procedure swap(var i, j: longint);
var
  d: longint;
begin
  d := x[i];
  x[i] := x[j];
  x[j] := d;
  d := y[i];
  y[i] := y[j];
  y[j] := d;
end;

function compare(i, j: longint): boolean;
begin
  if (max(x[i], y[i]) < max(x[j], y[j])) or ((max(x[i], y[i]) = max(x[j], y[j])) and ((x[i] < x[j]) or ((x[i] = x[j]) and (y[i] > y[j])))) then
    result := true
  else
    result := false;
end;

procedure sort(l, r: longint);
var
  i, j, tx, ty: longint;
begin
  i := l;
  j := r;
  x[0] := x[(l + r) div 2];
  y[0] := y[(l + r) div 2];
  repeat
    while compare(i, 0) do inc(i);
    while compare(0, j) do dec(j);
    if i <= j then begin
      swap(i, j);
      inc(i);
      dec(j);
    end;
  until i > j;
  if i < r then
    sort(i, r);
  if l < j then
    sort(l, j);
end;

function dist(i, j: longint): longint;
begin
  result := abs(x[i] - x[j]) + abs(y[i] - y[j]);
end;

begin
  read(n);
  for i := 1 to n do
    read(x[i], y[i]);

  sort(1, n);

  x[0] := 0;
  y[0] := 0;

  Lvl[0].l := 0;
  Lvl[0].r := 0;
  LvlCount := 1;
  Lvl[LvlCount].l := 1;
  for i := 2 to n do
    if max(x[i], y[i]) > max(x[i - 1], y[i - 1]) then begin
      with Lvl[LvlCount] do begin
        r := i - 1;
        len := dist(l, r);
        d[1] := dist(Lvl[LvlCount - 1].l, l);
        d[2] := dist(Lvl[LvlCount - 1].l, r);
        d[3] := dist(Lvl[LvlCount - 1].r, l);
        d[4] := dist(Lvl[LvlCount - 1].r, r);
      end;
      inc(LvlCount);
      Lvl[LvlCount].l := i;
    end;

  with Lvl[LvlCount] do begin
    r := n;
    len := dist(l, r);
    d[1] := dist(Lvl[LvlCount - 1].l, l);
    d[2] := dist(Lvl[LvlCount - 1].l, r);
    d[3] := dist(Lvl[LvlCount - 1].r, l);
    d[4] := dist(Lvl[LvlCount - 1].r, r);
  end;

  l[0] := 0;
  r[0] := 0;
  for i := 1 to LvlCount do begin
    l[i] := min(l[i - 1] + Lvl[i].d[2], r[i - 1] + Lvl[i].d[4]) + Lvl[i].len;
    r[i] := min(l[i - 1] + Lvl[i].d[1], r[i - 1] + Lvl[i].d[3]) + Lvl[i].len;
  end;

  write(min(l[LvlCount], r[LvlCount]));
end.

program ProjectF;

uses
  Math;

type
  TLvl = record
    l, r, len: longint;
    d: array[1..4] of longint;
  end;

var
  n, i, LvlCount: longint;
  x, y, l, r: array[0..200000] of longint;
  Lvl: array[0..200000] of Tlvl;

procedure swap(var i, j: longint);
var
  d: longint;
begin
  d := x[i];
  x[i] := x[j];
  x[j] := d;
  d := y[i];
  y[i] := y[j];
  y[j] := d;
end;

function compare(i, j: longint): boolean;
begin
  if (max(x[i], y[i]) < max(x[j], y[j])) or ((max(x[i], y[i]) = max(x[j], y[j])) and ((x[i] < x[j]) or ((x[i] = x[j]) and (y[i] > y[j])))) then
    result := true
  else
    result := false;
end;

procedure sort(l, r: longint);
var
  i, j, m: longint;
begin
  i := l;
  j := r;
  m := (l + r) div 2;
  repeat
    while compare(i, m) do inc(i);
    while compare(m, j) do dec(j);
    if i <= j then begin
      swap(i, j);
      inc(i);
      dec(j);
    end;
  until i > j;
  if i < r then
    sort(i, r);
  if l < j then
    sort(l, j);
end;

function dist(i, j: longint): longint;
begin
  result := abs(x[i] - x[j]) + abs(y[i] - y[j]);
end;

begin
  x[0] := 0;
  y[0] := 0;

  read(n);
  for i := 1 to n do
    read(x[i], y[i]);

  sort(1, n);

  Lvl[0].l := 0;
  Lvl[0].r := 0;
  LvlCount := 1;
  Lvl[LvlCount].l := 1;
  for i := 2 to n do
    if max(x[i], y[i]) > max(x[i - 1], y[i - 1]) then begin
      with Lvl[LvlCount] do begin
        r := i - 1;
        len := dist(l, r);
        d[1] := dist(Lvl[LvlCount - 1].l, l);
        d[2] := dist(Lvl[LvlCount - 1].l, r);
        d[3] := dist(Lvl[LvlCount - 1].r, l);
        d[4] := dist(Lvl[LvlCount - 1].r, r);
      end;
      inc(LvlCount);
      Lvl[LvlCount].l := i;
    end;

  with Lvl[LvlCount] do begin
    r := n;
    len := dist(l, r);
    d[1] := dist(Lvl[LvlCount - 1].l, l);
    d[2] := dist(Lvl[LvlCount - 1].l, r);
    d[3] := dist(Lvl[LvlCount - 1].r, l);
    d[4] := dist(Lvl[LvlCount - 1].r, r);
  end;

  l[0] := 0;
  r[0] := 0;
  for i := 1 to LvlCount do begin
    l[i] := min(l[i - 1] + Lvl[i].d[2], r[i - 1] + Lvl[i].d[4]) + Lvl[i].len;
    r[i] := min(l[i - 1] + Lvl[i].d[1], r[i - 1] + Lvl[i].d[3]) + Lvl[i].len;
  end;

  write(min(l[LvlCount], r[LvlCount]));
end.