{
TASK: KORTELES
LANG: PASCAL
}
program korteles;
  const PRF = 'KORTELES.DAT';
        RZF = 'KORTELES.REZ';
        MAX = 100000;
        MAXS = 2000*2;
  type kortele = record
                   a, b: longint;
                 end;
       Tmas = array [1..MAX] of kortele;
       Tmass = array [-MAXS..MAXS] of longint;

  var N: longint;
      kort: Tmas;
      kiek: Tmass;

  procedure spresti (var sk: longint);
    var i, nr, virs: longint;
  begin
    { randame vidurá }
    i := 0;
    nr := -MAXS-1;
    while i < N div 2 do
      begin
        nr := nr + 1;
        i := i + kiek[nr];
      end;
    { randame spendiná }
    sk := 0; virs := i - N div 2;
    for i := 1 to N do
      if kort[i].a+kort[i].b < nr
         then sk := sk + kort[i].a
      else if kort[i].a+kort[i].b > nr
              then  sk := sk - kort[i].b
      else if kort[i].a+kort[i].b=nr
              then if virs > 0
                      then begin
                             virs := virs - 1;
                             sk := sk - kort[i].b
                           end
                       else sk := sk + kort[i].a;
  end; { spræsti }

  procedure skaityti (var N: longint; var k: Tmas; var kiek: Tmass);
    var i, tarp, suma: longint;
        f: text;
  begin
    { inicializuojamas masyvas }
    for i := -MAXS to MAXS do
      kiek[i] := 0;
    assign (f, PRF);
    reset (f);
    readln (f, N);
    for i := 1 to N do
      begin
        readln (f, kort[i].a, kort[i].b);
        if kort[i].a > kort[i].b
           then begin
                  tarp := kort[i].a;
                  kort[i].a := kort[i].b;
                  kort[i].b := tarp;
                end;
       suma := kort[i].a+kort[i].b;
       kiek[suma] := kiek[suma] + 1;
      end;
    close (f);
  end; { skaityti }

  procedure rasyti (sk: longint);
    var f: text;
  begin
    assign (f, RZF);
    rewrite (f);
    writeln (f, sk);
    close (f);
  end; { raðyti }

  var sk: longint;
begin
  skaityti (N, kort, kiek);
  spresti (sk);
  rasyti (sk);
end.
