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 Java8 (OpenJDK 1.8.0) (judge verdict: Time Limit Exceeded)

import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			
			String S = scan.next();
			char[] c = new char[S.length()];
			int[] s = new int[S.length()];
			StringBuffer sb = new StringBuffer();
			StringBuffer sc = new StringBuffer();
			
			sb.append(S);
			c = S.toCharArray();
			
			int count = 0;
			int ok = 0;
			
			while(true) {
			
			
			
			boolean nozoketa = false;
	
			if(sb.length()<2) {
				break;
			}else {
				int k = sb.length();
	
			for(int i= 0;i<sb.length()-1;i++) {
				String A = sb.toString().substring(i, i+1);//一文字
				String B = sb.toString().substring(i+1, i+2);
				
				if(!A.equals("X")&&!B.equals("X")&&!A.equals(B)) {
					nozoketa =true;
					sb.replace(i, i+1, "X");
					sb.replace(i+1, i+2, "X");
					count++;
					count++;
				}
			}
			
			if(nozoketa==false)break;
			
			//System.out.println(sb.toString());
			
			for(int i = 0;i<sb.length();i++) {
				if(!sb.toString().substring(i, i+1).equals("X")) {
					sc.append(sb.toString().substring(i, i+1));
				}
			}
			
			//System.out.println(sc);
			sb.delete(0, k);
			sb.append(sc.toString());
			sc.delete(0, k);
			//System.out.println(sb);
			//System.out.println(nozoketa);
			}
			
			//}while(ok==0);
			}
			
			System.out.println(count);
			
		}	
	}
}