input1 = gets
num1 = input1.to_i

ary1 = [num1]
for num in 0..num1 - 1 do
  input2 = gets.split(" ")
  ary1.push([input2[0].to_i, input2[1].to_i])
end 


suma = 0
sumb = 0
while ary1.length > 0  do
  i = 0
  ary1 = ary1.sort_by {|x| [-x[1], i += 1]}.sort_by {|x| [-x[0], i += 1]}
  suma += ary1[0][0]
  ary1.delete_at(0)

  if ary1.length == 0 then
    break
  end

  i = 0
  ary1 = ary1.sort_by {|x| [-x[0], i += 1]}.sort_by {|x| [-x[1], i += 1]}
  sumb += ary1[0][1]
  ary1.delete_at(0)
end
puts (suma - sumb).to_s