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
#include <bits/stdc++.h>
using namespace std;

string in;
int typ[30];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int i,r=0;
    long long ans=0;
    cin>>in;
    typ[(int)('a'-'a')]=-1;
    typ[(int)('b'-'a')]=1;
    typ[(int)('c'-'a')]=1;
    typ[(int)('d'-'a')]=1;
    typ[(int)('e'-'a')]=-1;
    typ[(int)('f'-'a')]=1;
    typ[(int)('g'-'a')]=1;
    typ[(int)('h'-'a')]=1;
    typ[(int)('i'-'a')]=-1;
    typ[(int)('j'-'a')]=1;
    typ[(int)('k'-'a')]=1;
    typ[(int)('l'-'a')]=1;
    typ[(int)('m'-'a')]=1;
    typ[(int)('n'-'a')]=1;
    typ[(int)('o'-'a')]=-1;
    typ[(int)('p'-'a')]=1;
    typ[(int)('q'-'a')]=1;
    typ[(int)('r'-'a')]=1;
    typ[(int)('s'-'a')]=1;
    typ[(int)('t'-'a')]=1;
    typ[(int)('u'-'a')]=-1;
    typ[(int)('v'-'a')]=1;
    typ[(int)('w'-'a')]=1;
    typ[(int)('x'-'a')]=1;
    typ[(int)('y'-'a')]=-1;
    typ[(int)('z'-'a')]=1;
    for(i=0;i<in.size();i++)
    {
        r=max(r,min(i+2,(int)in.size()));
        while(r<in.size()&&abs(typ[(int)(in.at(r)-'a')]+typ[(int)(in.at(r-1)-'a')]+typ[(int)(in.at(r-2)-'a')])!=3)
        {
            r++;
        }
        ans+=(long long)(in.size()-r);
    }
    cout<<ans;
}