1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <bits/stdc++.h>
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	string s;
	int a, b, c, ilosc = 0;
	cin >> s;
	for(int i = 0; i < s.size(); i++){
		a = 0; b = 0; c = 0;
		for(int j = i; j < s.size(); j++){
			if(s[j] == 'a') a++;
			else if(s[j] == 'b') b++;
			else c++;
			if((a == b && b == c) || (a == b && c == 0) || (a == c && b == 0) || (b == c && a == 0)) ilosc++;
			else if((a == 0 && b == 0) || (a == 0 && c == 0) || (b == 0 && c == 0)) ilosc++;
		}
	}
	cout << ilosc;
	return 0;
}