var lines = [];
var readline = require('readline');
var rl = readline.createInterface({
  input: process.stdin,
  output:process.stdout
});

rl.on('line',function(x){
  lines.push(x);
});

rl.on('close',function(){
  var n = Number(lines[0]);
  var a = [];
  var b = [];
  var a_sum = 0;
  var b_sum = 0;
  var indexOfMaxValue_a = 0;
  var indexOfMaxValue_b = 0;

  var a_result = 0;
  var b_result = 0;
  for(var i=1;i<=n;i++){
    tmp = lines[i].split(" ");
    a_sum = a_sum + Number(tmp[0]);
    b_sum = b_sum + Number(tmp[1]);
    a.push(Number(tmp[0]));
    b.push(Number(tmp[1]));
  }


  for(var i=0;i<n;i++){
    indexOfMaxValue_a = a.reduce((iMax, x, i, arr) => x > arr[iMax] ? i : iMax, 0);
    indexOfMaxValue_b = b.reduce((iMax, x, i, arr) => x > arr[iMax] ? i : iMax, 0);

    if(a[indexOfMaxValue_a]/a_sum > b[indexOfMaxValue_b]/b_sum){
      a_result = a_result + a[indexOfMaxValue_a];
      a.splice(indexOfMaxValue_a,1);
      b.splice(indexOfMaxValue_a,1);
    }
    else{
      a_result = a_result + a[indexOfMaxValue_b];
      a.splice(indexOfMaxValue_b,1);
      b.splice(indexOfMaxValue_b,1);
    }
    i++;
    if(n === i){break;}

    indexOfMaxValue_a = a.reduce((iMax, x, i, arr) => x > arr[iMax] ? i : iMax, 0);
    indexOfMaxValue_b = b.reduce((iMax, x, i, arr) => x > arr[iMax] ? i : iMax, 0);

    if(a[indexOfMaxValue_a]/a_sum > b[indexOfMaxValue_b]/b_sum){
      b_result = b_result + b[indexOfMaxValue_a];
      a.splice(indexOfMaxValue_a,1);
      b.splice(indexOfMaxValue_a,1);
    }
    else{
      b_result = b_result + b[indexOfMaxValue_b];
      a.splice(indexOfMaxValue_b,1);
      b.splice(indexOfMaxValue_b,1);
    }

  }

  console.log(a_result-b_result);

});
