#K67822. Count Special Binary Substrings
Count Special Binary Substrings
Count Special Binary Substrings
Given a binary string s
, a special substring is defined as a contiguous substring that satisfies the following two conditions:
- The number of
0
s is equal to the number of1
s, i.e., \(\#0 = \#1\). - All the
0
s and all the1
s in the substring must occur in consecutive groups. In other words, if the substring is partitioned into two consecutive groups, then one group consists entirely of0
s and the other entirely of1
s.
Your task is to count the total number of special substrings present in the given binary string. For example, in the string "00110011", there are 6 special substrings.
Note: The answer should be computed by considering substrings that appear in the original order without rearranging characters.
inputFormat
The input consists of a single line containing a binary string s
(i.e., a string composed of characters '0' and '1' only).
outputFormat
Output a single integer, which is the count of special substrings in the given binary string.
## sample00110011
6