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
#include <iostream>
using namespace std;

int main()
{
    char word[300001];
    cin >> word;
    int a, b, c, j;
    int counter = 0;
    int i = 0;
    while(word[i] != '\0')
    {
        j = i;
        a = b = c = 0;
        while(word[j] != '\0')
        {
            switch(word[j])
            {
                case 'a':
                    a++;
                    break;
                case 'b':
                    b++;
                    break;
                case 'c':
                    c++;
            }
            if((a == b || a == 0 || b == 0) && (a == c || a == 0 || c == 0) && (b == c || b == 0 || c == 0))
                counter++;
            j++;
        }
        i++;
    }
    cout << counter;
}