cswork / OAOpen practice workspace

SalesforceOA #26

Max Number of Operations

HardJudge-ready

Topics (AI-labelled)StringsGreedy

You are given a string s. In one operation, choose three consecutive characters s[i], s[i+1], s[i+2]; if and only if s[i]=s[i+1] and s[i+1]≠s[i+2], replace s[i+2] with s[i]. Operations can be performed in any order and any number of times; find the maximum number of operations that can be performed.

Input

One line containing the string s. 1≤length of s≤200000, consisting only of lowercase English letters.

Output

Output one integer: the maximum number of operations.

Example 1

Input:

accept

Output:

3

Example 2

Input:

aabaab

Output:

2

Example 3

Input:

aabba

Output:

4

Example notes

Example 1: in "accept", cc changes e, p, and t to c one after another, 3 times in total. Example 2: in "aabaab", first use the later aa to change the final b to a, then use the leading aa to change the 3rd character, b, to a, 2 times in total. Example 3: in "aabba", first use bb to change the final a to b, giving "aabbb", then use aa to change the three b's to a one after another, 4 times in total.

Editorial

Loading solution…