Longest balanced binary substring

In a string of 0s and 1s, find the longest substring with the same number of 0s and 1s. Print its length (0 if there is none).

Reported in: Capgemini (2026 batch) (memory-based)

Input

One line: the binary string.

Output

The length.

Constraints

1 ≤ length ≤ 10^5.

Example 1

Input:
1101000

Output:
6

Example 2

Input:
111

Output:
0

Hint: Treat 0 as −1 and 1 as +1; equal prefix sums mark a balanced stretch. Store the first index of each prefix sum.

All coding practice