{$M 65520,0,655360}
const
  maxn=10000;
  inputfile='soldiers.in';
  outputfile='soldiers.out';
type
  listtype=array[1..maxn]of integer;
var
  px:listtype;
  n:integer;
  sumx,sumy:longint;
procedure swap(var x,y:integer);
  var t:integer;
  begin
    t:=x; x:=y; y:=t;
  end;
procedure heapsort(var list:listtype);
  var i,x,f,v:integer;
      finish:boolean;
  begin
    {Make Heap}
    for i:=2 to n do begin
      v:=list[i];
      x:=i;
      finish:=false;
      repeat
        f:=x div 2;
        if list[f]<v then begin
           list[x]:=list[f];
           x:=f;
        end else finish:=true;
      until (x=1) or finish;
      list[x]:=v;
    end;
    {Heap Sort}
    for i:=n downto 2 do begin
      v:=list[i];
      list[i]:=list[1];
      x:=1;
      finish:=false;
      repeat
        list[x]:=v;
        f:=x;
        if (x*2<i) and (list[x*2]>list[f]) then f:=x*2;
        if (x*2+1<i) and (list[x*2+1]>list[f]) then f:=x*2+1;
        if f=x then finish:=true
               else begin
                      list[x]:=list[f];
                      x:=f;
                    end;
      until finish;
    end;
  end;
procedure init;
  var mid,i,low,j:integer;
      py:listtype;
  begin
    assign(input,inputfile);
    reset(input);
    read(n);
    for i:=1 to n do read(px[i],py[i]);
    close(input);
    mid:=(n+1) div 2;
    heapsort(py);
    sumy:=0;
    for i:=1 to n do sumy:=sumy+abs(py[i]-py[mid]);
  end;
function add(x:longint):boolean;
  var num,i:integer;
  begin
    num:=0;
    for i:=1 to n do
      if x+i>px[i] then inc(num)
                   else dec(num);
    add:=num>0;
  end;
procedure main;
  var i,j:integer;
      high,low,mid:longint;
  begin
    heapsort(px);
    low:=px[1]-n;
    high:=px[n];
    while low<high do begin
      mid:=(low+high) div 2;
      if mid=high then mid:=low;
      if add(mid) then high:=mid
                  else low:=mid+1;
    end;
    mid:=low;
    sumx:=0;
    for i:=1 to n do sumx:=sumx+abs(mid+i-1-px[i]);
  end;
begin
  init;
  main;
  assign(output,outputfile);
  rewrite(output);
  writeln(sumx+sumy);
  close(output);
end.

