1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>

using namespace std;

int t[30] = {1,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0};
long long str[200005];
long long m[200005];
long long dist[200005];

int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin>>s;

  if( s.size() < 3 )
  {
    cout<<0<<endl;
    return 0;
  }

  for(int i=0; i<s.size(); i++)
    str[i] = t[ s[i] - 'a' ];

  int c=1;
  for(int i=1; i<=s.size(); i++)
  {
    if(str[i-1] == str[i])
      c++;
    else
      c=1;
    if(c >= 3) m[i] = 1;
  }

  m[s.size()] = 1;
  for(int i=s.size(); i>=0; i--)
  {
    if(m[i]) dist[i] = 0;
    else dist[i] = dist[i+1]+1;
  }

  dist[s.size()] = 0;
  long long ans=0;
  long long n = s.size();
  for(long long i=0; i<=s.size()-3; i++)
  {
    ans += n-i-2-dist[i+2];
  }

  cout<<ans;

  return 0;
}