cswork / OAOpen practice workspace

AmazonOA #56

Special Strings (Binary Substrings)

Estimated HardJudge-ready

Topics (AI-labelled)StringsPrefix & RangesBits & Math

Count the non-empty contiguous binary substrings in which the number of 0s is exactly the square of the number of 1s.

Input

A single line containing a binary string of length 1..100000.

Output

Output a single integer answer.

Example 1

Input:

010001

Output:

4

Example 2

Input:

0

Output:

0

Example 3

Input:

01

Output:

1

Example notes

Example 1: the two adjacent 01, the one adjacent 10, and the whole string (two 1s and four 0s) are valid, 4 in total. Example 2: with only 0s the condition cannot hold, so the answer is 0. Example 3: one 0 and one 1 satisfy 1=1², so the answer is 1.

Editorial

Loading solution…