atcoder#ARC113C. [ARC113C] String Invasion

[ARC113C] String Invasion

Score : 500500 points

Problem Statement

Given is a string SS of length NN. Let sis_i denote the ii-th character of SS. Find the maximum number of times the following operation can be done.

  • Choose three consecutive characters in SS, si,si+1,si+2(1iS2)s_i,s_{i+1},s_{i+2}\quad (1\leq i\leq |S|-2), such that si=si+1si+2s_i=s_{i+1}\neq s_{i+2}, and replace si+2s_{i+2} with sis_i.

Constraints

  • 3S2×1053 \leq |S| \leq 2\times 10^5
  • SS consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

SS

Output

Print the maximum number of times the operation can be done.

accept
3

We can do the operation three times, as follows:

  • do it with i=2i=2, changing the string to acccpt;
  • do it with i=3i=3, changing the string to acccct;
  • do it with i=4i=4, changing the string to accccc.
atcoder
0
anerroroccurred
16