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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <bits/stdc++.h>
#include <vector>
using namespace std;

struct p{
    int a;
    int b;
    int c;
};

vector<p> word;
string w;
int main(){
    p z;
    z.a =0;
    z.b = 0;
    z.c = 0;

    word.push_back(z);
    getline(std::cin, w);
    int a = 0;
    int b = 0;
    int c = 0;
    for(int i =0;i<w.size();i++){
        if(w[i]=='a'){
            a += 1;

        }
        else if(w[i]=='b'){
            b += 1;
            
        }
        if(w[i]=='c'){
            c += 1;
            
        }
        p tmp;
        tmp.a = a;
        tmp.b = b;
        tmp.c = c;
        word.push_back(tmp);


    }
    for(auto i: word){
//            cout << i.a << " " << i.b <<" "<< i.c << endl;
        }
//        cout << endl;
    int sum =0;
    for(int i=1;i<=w.size();i++){

        for(int j =0;j<=w.size()-i;j++){
//            cout << word[j+i].a << " " << word[j].a << endl;
            int ta = word[j+i].a-word[j].a;
            int tb = word[j+i].b-word[j].b;
            int tc = word[j+i].c-word[j].c;
            int control = max(ta,max(tb, tc));
//            cout << ta << " " << tb <<" " << tc << " ";
            if(ta == control || ta == 0){
                if(tb == control || tb == 0){
                    if(tc == control || tc == 0){
         //               cout << "true" << endl;
                        sum +=1;
                    }
       //             else cout << "false" << endl;
                    
                }
 //               else cout << "false" << endl;
            }
//            else cout << "false" << endl;

        }
    }
    cout << sum << endl;

}