cswork / OAOpen practice workspace

SalesforceOA #10

Count Substrings

Estimated EasyJudge-ready

Topics (AI-labelled)StringsTwo Pointers

Count the contiguous substrings of the form 0^k1^k or 1^k0^k with k≥1. Substrings are counted by their start and end indices, so repeated content is counted separately; this is not every substring with equal numbers of 0s and 1s.

Input

One line containing a non-empty binary string. On this site the length is 1..200000.

Output

Output the number of qualifying substrings.

Example 1

Input:

10101

Output:

4

Example 2

Input:

00110011

Output:

6

Example 3

Input:

000

Output:

0

Example notes

The answers are 4, 6, and 0, respectively.

Editorial

Loading solution…