C - Unification Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300

問題文

机の上に N 個のキューブが縦に積まれています。長さ N の文字列 S が与えられます。

下から i 番目のキューブの色は、Si 文字目が 0 のとき赤色、1 のとき青色です。

あなたは、赤色のキューブと青色のキューブが隣り合っているような部分を選んで、それら 2 個のキューブを取り除く操作を何度でも行えます。

このとき、取り除いたキューブの上にあったキューブは真下の物体の上に落下します。

最大で何個のキューブを取り除けるでしょうか。

制約

  • 1 \leq N \leq 10^5
  • |S| = N
  • S の各文字は 0 または 1 である。

入力

入力は以下の形式で標準入力から与えられる。

S

出力

最大で何個のキューブを取り除けるかを出力せよ。


入力例 1

0011

出力例 1

4

以下の順に操作を行うと 4 個全てのキューブを取り除けます。

  • 下から 2 番目のキューブと 3 番目のキューブを取り除きます。その結果、下から 4 番目のキューブが下から 1 番目のキューブの上に落下します。
  • 下から 1 番目のキューブと 2 番目のキューブを取り除きます。

入力例 2

11011010001011

出力例 2

12

入力例 3

0

出力例 3

0

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