n=gets.to_i;
a=[]
n.times{|i|
  a<<gets.split.map(&:to_i)
  a[-1].push i
}
b=a.sort_by{|i|i[0]}.sort_by{|i|i[1]}
c=a.sort_by{|i|i[1]}.sort_by{|i|i[0]}
sum=0
n.times{|j|
  if j%2==0
    sum+=b[0][0]
    c.delete_if{|item| item[2]==b[0][2]}
    b.delete_at 0
  else
    sum-=c[0][1]
    b.delete_if{|item| item[2]==c[0][2]}
    c.delete_at 0
  end
}
puts sum