local DBG = false
function dbgpr(...)
    if DBG then
        io.write("[dbg]")
        print(...)
    end
end
function dbgpr_t(tbl)
    if DBG then
        dbgpr(tbl)
        io.write("[dbg]")
        for i,v in ipairs(tbl) do
            io.write(i)
            io.write(":")
            io.write(tostring(v))
            io.write(" ")
        end
        print("")
    end
end

function parse_problem()
    local tbl = {}
    local S = io.read("l"):gsub("[^%d]", "")
    dbgpr(S, string.len(S))
    --local S_split = {S:byte(1, S:len())}
    local cur_char = nil
    local cur_succ = nil
    for _,v in ipairs({S:byte(1, S:len())}) do
        if v ~= cur_char then
            if cur_succ ~= nil then
                table.insert(tbl, cur_succ)
            end
            cur_char = v
            cur_succ = 1
        else
            cur_succ = cur_succ + 1
        end
    end
    if cur_succ ~= nil then
        table.insert(tbl, cur_succ)
    end
    dbgpr_t(tbl)
    return tbl
end

function main()
    local tbl = parse_problem()
    local del_count = 0
    local start = 1
    while start <= (#tbl - 1) do
        local a, b = tbl[start], tbl[start + 1]
        if a == b then
            del_count = del_count + a
            -- remove a, b
            start = start + 2
        elseif a > b then
            local r = a - b
            del_count = del_count + b
            -- remove b, merge r into c
            start = start + 2
            if start <= #tbl then
                tbl[start] = tbl[start] + r
            end
        else
            -- b > a
            local r = b - a
            del_count = del_count + a
            -- remove a
            start = start + 1
            -- update b
            tbl[start] = r
        end
    end
    local ans = del_count * 2
    print(ans)
end

main()
