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
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#include <iostream>
#include <vector>
using namespace std;

int64_t sumN(int64_t n)
{
    return n * (n + 1) / 2;
}

int main()
{
    FAST
        string s;
    cin >> s;
    int64_t total = 0;
    vector<int> occ(3, 0);
    for (int i = 0; i < s.size(); i++)
    {
        occ = {0, 0, 0};
        for (int j = i; j < s.size(); j++)
        {
            occ[s[j] - 'a']++;
            if (((!occ[0]) + (!occ[1]) + (!occ[2])) == 2 ||
                (occ[0] == occ[1] && occ[1] == occ[2]) ||
                (!occ[0] && occ[1] == occ[2]) ||
                (!occ[1] && occ[0] == occ[2]) ||
                (!occ[2] && occ[0] == occ[1]))
            {
                total++;
            }
        }
    }
    cout << total << endl;
}