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 C (GCC 5.4.1) (judge verdict: Time Limit Exceeded)

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>

typedef struct cell { char ch; struct cell *next, *prev; } *cellp;
typedef struct data { cellp head; int len; } *datap;

datap data_new(int size, char *str) {
    datap p = (datap)malloc(sizeof(struct data));
    p->head = (cellp)malloc(sizeof(struct cell));
    p->len = size;
    cellp cur, bef = p->head; int i;
    for(i = 0; i < size; ++i) {
        cur = (cellp)malloc(sizeof(struct cell));
        bef->next = cur; cur->prev = bef; bef = cur;
    }
    p->head->prev = cur; cur->next = p->head;
    
    //データの挿入
    cur = p->head->next;
    for(i = 0; i < size; ++i) {
        cur->ch = str[i]; cur = cur->next;
    }

    return p;
}

void delete(datap p, cellp cur) {
    if( cur == p->head) { return ; }
    cur->prev->next = cur->next;
    cur->next->prev = cur->prev;
    free(cur); --p->len;
}

void prdata(datap p) {
    cellp cur = p->head->next;
    printf("len: %d\n", p->len);
    while( cur != p->head) {
        printf("%c ", cur->ch);
        cur = cur->next; 
    }
    printf("\n");
}

int check(datap p) {
    cellp cur = p->head->next;
    int ans = 0; char a1, a2;
    while( cur != p->head && cur->next != p->head ){
        a1 = cur->ch; cur = cur->next;
        a2 = cur->ch; cur = cur->next;
        if( (a1 == '0' && a2 == '1') || (a1 == '1' && a2 == '0') ) {
            delete(p, cur->prev); delete(p, cur->prev);
            ans +=2;
        } else {
            cur = cur->prev;
        }
    }
    return ans;
}

void solve(datap p, int *ans) {
    *ans = 0;
    int i;
    while( (i = check(p)) != 0) {
        *ans += i;
    }
}

#define LEN (1e5 + 5)

int main() 
{
    int ans = 0;
    char *str = (char *)malloc(LEN * sizeof(char));
    scanf("%s", str);
    datap p = data_new(strlen(str), str);
    
    //prdata(p);
    /*
    cellp cur = p->head->next;
    printf("len: %d\n", p->len);
    while( cur != p->head) {
        printf("%c ", cur->ch);
        cur = cur->next;
    }
    printf("\n");
    */

    solve(p, &ans);
    /*
    char a1, a2; int check;
    do {
        check = 0; cur = p->head->next;
        while( cur != p->head && cur->next != p->head) {
            a1 = cur->ch; cur = cur->next;
            a2 = cur->ch; cur = cur->next;
            if( (a1 == '0' && a2 == '1') || (a1 == '1' && a2 == '0') ) {
                delete(p, cur->prev); delete(p, cur->prev);
                check += 2;
            } else {
                cur = cur->prev;
            }
        }
        ans += check;
        prdata(p); printf("check : %d\n", check);
    } while ( check != 0) ;
    */

    printf("%d\n", ans);
    return 0;
}