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
#include <iostream>
#include <string.h>


using namespace std;

char s[300010];

int main()
{
    int nr[3], i, j;
    cin >> s; //cout << s << endl;
    int len = strlen(s);
    int ret = len + len -1;
//cout << s[0] << endl;    

    for (i = 0; i < len - 2; i++){
        nr[0] = nr[1] = nr[2] = 0; j = i;
//if (i > 7) cout << "9bomb" << endl;
        nr[s[j++] - 'a']++; nr[s[j++] - 'a']++; nr[s[j++] - 'a']++;
                //    cout << nr[0] << " " << nr[1] << " " << nr[2] << endl;
        while (j < len){
            if (nr[0] == nr[1] && nr[1] == nr[2]
                || !nr[0] && nr[1] == nr[2]
                || !nr[1] && nr[0] == nr[2]
                || !nr[2] && nr[0] == nr[1]
                || !nr[0] && !nr[1]
                || !nr[1] && !nr[2]
                || !nr[0] && !nr[2]
                )
                { ret++; //cout << "x " << i << " " << j << endl; 
               ///     cout << nr[0] << " " << nr[1] << " " << nr[2] << endl;
                }
            nr[s[j++] - 'a']++;
            ///cout << "x " << i << " " << j << endl; 
        }
        if (nr[0] == nr[1] && nr[1] == nr[2]
                || !nr[0] && nr[1] == nr[2]
                || !nr[1] && nr[0] == nr[2]
                || !nr[2] && nr[0] == nr[1]
                || !nr[0] && !nr[1]
                || !nr[1] && !nr[2]
                || !nr[0] && !nr[2]
                )
            { ret++; //cout << "x " << i << " " << j << endl; 
                ///cout << nr[0] << " " << nr[1] << " " << nr[2] << endl;
            }
        }

    cout << ret;
    return 0;
}