input = STDIN.read.split("\n").map{|l| l.split(" ").map{|a| a.to_i}}

N = input.shift[0]

sai = input.map.with_index.sort_by {|r| [r[0],r[1]]}.reverse.map(&:last)
sbi = input.map.with_index.sort_by {|r| [r[1], r[0]]}.reverse.map(&:last)

ate = 0
current_turn = :a
current_col = 0

pt = {
    a: 0,
    b: 0
}

while ate < N

    ai = nil
    while ai == nil
        ti = sai.first
        if input[ti] == nil
            sai.shift
        else
            ai = ti
        end
    end

    bi = nil
    while bi == nil
        ti = sbi.first
        if input[ti] == nil
            sbi.shift
        else
            bi = ti
        end
    end

    i = (current_turn == :a) ? ai : bi
    if ai == bi
        if current_turn == :a
            pt[:a] = pt[:a] + input[ai][0]
            input[ai] = nil
        else
            pt[:b] = pt[:b] + input[bi][1]
            input[bi] = nil
        end
    else
        ah = input[ai][0]
        bh = input[bi][1]
        if current_turn == :a
            if ah > bh
                pt[:a] = pt[:a] + input[ai][0]
                input[ai] = nil
            elsif bh > ah
                pt[:a] = pt[:a] + input[bi][0]
                input[bi] = nil
            else
                if input[bi][0] >= input[ai][1]
                    pt[:a] = pt[:a] + input[bi][0]
                    input[bi] = nil
                else
                    pt[:a] = pt[:a] + input[ai][0]
                    input[ai] = nil
                end
            end
        else
            if bh > ah
                pt[:b] = pt[:b] + input[bi][1]
                input[bi] = nil
            elsif ah > bh
                pt[:b] = pt[:b] + input[ai][1]
                input[ai] = nil
            else
                if input[ai][1] >= input[bi][0]
                    pt[:b] = pt[:b] + input[ai][1]
                    input[ai] = nil
                else
                    pt[:a] = pt[:a] + input[bi][1]
                    input[bi] = nil
                end
            end
        end
    end


    ate = ate + 1
    current_turn = (current_turn == :a) ? :b : :a
    current_col = (current_turn == :a) ? 1 : 0
end

puts pt[:a] - pt[:b]