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: Time Limit Exceeded)

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let s = read::<String>();
    let n = s.len();
    if n < 2 {
        println!("{}", 0);
        return;
    }

    let mut v = s.chars().collect::<Vec<char>>();
    let mut count = 0;

    loop {
        let len = v.len();
        if len == 0 {break;}
        for i in 0..len-1 {
            if v[i] == 'X' {
                continue;
            } else if v[i+1] != 'X' && v[i] != v[i+1] {
                v[i] = 'X';
                v[i+1] = 'X';
            }
        }

        let xcount = v.iter().filter(|&c| *c=='X').count();
        if xcount == 0 {
            break;
        } else {
            count += xcount;
        }
        v = v.iter().filter(|&c| *c!='X').map(|&c| c).collect::<Vec<char>>();
    }

    println!("{}", count);

    /*
    let mut f = false;
    let mut a = v[0];
    let mut count = 1;
    let mut total = 0;
    for i in 1..n {
        if f == false { // 準備フェーズ
            if v[i] == a {
                count += 1;
            } else {
                a = v[i];
                f = !f;
                total += 2;
                count -= 1;
            }
        } else { // 回収フェーズ
            if v[i] == a {
                if count == 0 {
                    f = !f;
                    count += 1;
                } else {
                    total += 2;
                    count -= 1;
                }
            } else {
                f = !f;
                count = 1;
            }
        }
    }
    println!("{}", total);
    */


    /* vec input
    let v = read_vec::<u32>();
    let a = v[0];
    let b = v[1];
    let c = v[2];
    */

    /* loop pattern
    let mut count = 0;
    loop {
        if  { break; }
        count += 1;
    }
    println!("{}", count);
    */

    /* yes/no pattern
    yn(a == b);
    */
}