#K67822. Count Special Binary Substrings

    ID: 32728 Type: Default 1000ms 256MiB

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 0s is equal to the number of 1s, i.e., \(\#0 = \#1\).
  • All the 0s and all the 1s 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 of 0s and the other entirely of 1s.

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.

## sample
00110011
6