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

using namespace std;

string slowo;

bool czy(int p, int k){
    int la = 0;
    int lb = 0;
    int lc = 0;
    for (int i = p; i <= k; i++){
        if (slowo[i] == 'a'){
            la += 1;
        }
        if (slowo[i] == 'b'){
            lb += 1;
        }
        if (slowo[i] == 'c'){
            lc += 1;
        }
    }
    if (la == lb && la == lc){
        return true;
    }
    else if (la == 0 && lb == lc){
        return true;
    }
    else if (lb == 0 && la == lc){
        return true;
    }
    else if (lc == 0 && lb == la){
        return true;
    }
    else if (la == 0 && lb == 0){
        return true;
    }
    else if (la == 0 && lc == 0){
        return true;
    }
    else if (lc == 0 && lb == 0){
        return true;
    }
    else {
        return false;
    }
}

int main()
{
    cin >> slowo;
    int wynik = 2 * slowo.length() - 1;
    for (int e = 0; e < slowo.length(); e++){
        for (int f = (e + 2); f < slowo.length(); f++){
            if (czy(e, f)){
                wynik += 1;
            }
        }
    }
    
    cout << wynik;

    return 0;
}