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 Rust (1.15.1) (judge verdict: Runtime Error)

use std::fs;
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: expr) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let (n, a, b, c): (usize, usize, usize, usize) = parse!(it, 4);
    let l: Vec<usize> = (0..n).map(|_| parse!(it)).collect();
    let mut ret = std::usize::MAX / 2;
    let diff = |x: usize, y: usize| if x >= y { x - y } else { y - x };
    for i in 0..4usize.pow(n as u32) {
        let mut p = 0;
        let mut ca = 0;
        let mut cb = 0;
        let mut cc = 0;
        let mut i = i;
        for j in 0..n {
            match i & 3 {
                1 => {
                    if ca != 0 {
                        p += 10
                    };
                    ca += l[j]
                }
                2 => {
                    if cb != 0 {
                        p += 10
                    };
                    cb += l[j]
                }
                3 => {
                    if cc != 0 {
                        p += 10
                    };
                    cc += l[j]
                }
                _ => (),
            }
            i >>= 2;
        }
        p += diff(ca, a) + diff(cb, b) + diff(cc, c);
        ret = std::cmp::min(p, ret);
    }
    println!("{}", ret);
}

fn test() {
    let mut f = fs::File::open("foo.txt").unwrap();
    let mut s = String::new();
    f.read_to_string(&mut s).unwrap();
    solve(&s);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        5 100 90 80
98
40
30
21
80
        ";
        solve(s);
    }
}