Problem:
Score : 300 points

Problem Statement

There are N cubes stacked vertically on a desk.

You are given a string S of length N. The color of the i-th cube from the bottom is red if the i-th character in S is 0, and blue if that character is 1.

You can perform the following operation any number of times: choose a red cube and a blue cube that are adjacent, and remove them. Here, the cubes that were stacked on the removed cubes will fall down onto the object below them.

At most how many cubes can be removed?

Constraints

1 \leq N \leq 10^5

|S| = N

Each character in S is 0 or 1.

Input

Input is given from Standard Input in the following format:

S

Output

Print the maximum number of cubes that can be removed.

Sample Input 1

0011

Sample Output 1

4

All four cubes can be removed, by performing the operation as follows:

Remove the second and third cubes from the bottom. Then, the fourth cube drops onto the first cube.

Remove the first and second cubes from the bottom.

Sample Input 2

11011010001011

Sample Output 2

12

Sample Input 3

0

Sample Output 3

0

Solution in Lua (5.3.2) (judge verdict: Time Limit Exceeded)

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
    while #tbl >= 2 do
        local a, b = tbl[1], tbl[2]
        if a == b then
            del_count = del_count + a
            -- remove a, b
            table.remove(tbl, 2)
            table.remove(tbl, 1)
        elseif a > b then
            local r = a - b
            del_count = del_count + b
            -- remove b, merge r into c
            table.remove(tbl, 2)
            table.remove(tbl, 1)
            if #tbl >= 1 then
                tbl[1] = tbl[1] + r
            end
        else
            -- b > a
            local r = b - a
            del_count = del_count + a
            -- remove a
            table.remove(tbl, 1)
            -- update b
            tbl[1] = r
        end
    end
    local ans = del_count * 2
    print(ans)
end

main()