cswork / OAOpen practice workspace

AmazonOA #126

Count Special Strings

Estimated HardJudge-ready

Topics (AI-labelled)StringsPrefix & RangesBits & Math

Count the non-empty binary substrings in which the number of 0s equals the square of the number of 1s. Different index ranges are counted separately.

Input

One line with a 01 string of length 1..100000.

Output

Output a single integer answer.

Example 1

Input:

010001

Output:

4

Example 2

Input:

10010

Output:

3

Example 3

Input:

0

Output:

0

Example notes

Example 1: the three length-2 ranges 01, 01 and 10, plus the whole 010001, 4 in total. Example 2: three adjacent 01 or 10 ranges, 3 in total. Example 3: a single 0 does not satisfy 1=0², so the answer is 0.

Editorial

Loading solution…