#K81132. Count Binary Substrings

    ID: 35686 Type: Default 1000ms 256MiB

Count Binary Substrings

Count Binary Substrings

You are given a binary string \(s\) consisting only of '0's and '1's. Your task is to count the number of non-empty substrings that have an equal number of consecutive '0's and '1's.

A valid substring consists of a contiguous block of 0's followed immediately by a contiguous block of 1's, or vice versa, such that the two blocks have the same length. In mathematical terms, if you split the string into groups where each group is a consecutive sequence of identical characters, then for every adjacent pair of groups \(g_i\) and \(g_{i+1}\), the number of valid substrings contributed is \(\min(g_i, g_{i+1})\).

For example, given \(s = \texttt{00110011}\), the answer is 6.

inputFormat

The input consists of a single line containing the binary string \(s\). The string \(s\) contains only characters '0' and '1'.

outputFormat

Output a single integer representing the total number of valid binary substrings.

## sample
00110011
6