class String
    def val
        x = []
        x = self.split.map(&:to_i)
        return x[0]-x[1]
    end
end

N = gets.to_i
cuisine = []
N.times{
    s = gets.chomp
    cuisine << [s.val, s]
}

cuisine.sort!{|a,b|
     a[0] <=> b[0]
}

ht = [0]
ha = [0]
same = []
N.times{|i|
    hap = cuisine[i][1].split.map(&:to_i)
    if cuisine[i][0] == 0
        same << hap[0] 
    elsif i < (N+1)/2
        ht << hap[0]
    else
        ha << hap[1]
    end 
}

same.sort!
same.size.times{|i|
    same[-1-i] = same[-1-i]*(-1) if i % 2 == 1
}
sum = 0
sum = same.inject(:+) unless same.empty?

puts ht.inject(:+) - ha.inject(:+) + sum