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

bool eq(int a, int b, int c)
{
    if(a>c)
        swap(a,c);
    if(a>b)
        swap(a,b);
    if(b>c)
        swap(b,c);
    
    if(a == 0 && b == 0)
        return true;
    if(a == 0 && b == c)
        return true;
    if(a == b && b == c)
        return true;
        
    return false;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string sl;
    cin >> sl;
    long long wy = 0;
    for(int i = 0; i < sl.size(); i++)
    {
        int a = 0, b = 0, c = 0;
        for(int j = i; j < sl.size();j++)
        {
            if(sl[j] == 'a')
                a++;
            else if(sl[j] == 'b')
                b++;
            else if(sl[j] == 'c')
                c++;
             //cout << a << ' ' << b << ' ' << c << '\n';  
            if(eq(a,b,c))
            {
            //cout<<"ghfdg" <<"\n";
                //cout << a << ' ' << b << ' ' << c << '\n';  
                wy++;
            }
        }
    }
    cout << wy;
}