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
65
66
67
#include <bits/stdc++.h>

using std::cout;
using std::cin;
using std::ios_base;
using std::string;
using std::sort;
using std::max;
using std::min;
using std::vector;
using std::priority_queue;
using std::stack;
using std::endl;
using std::fixed;

#define be_faster_please ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long

bool spr(int a,int b,int c)
{
	if(a == b && b == c)
		return true;
	if(a == b && c == 0)
		return true;
	if(a == c && b == 0)
		return true;
	if(b == c && a == 0)
		return true;
	if(a == c && c == 0)
		return true;
	if(a == b && a == 0)
		return true;
	if(b == c && b == 0)
		return true;
	return false;
}
int main()
{
	be_faster_please;
	string s;
	cin >> s;
	ll ans = 0;
	for(int i=0;i<s.size();i++)
	{
		int a,b,c;
		a = b = c = 0;
		for(int j=i;j<s.size();j++)
		{
			switch(s[j])
			{
				case 'a':
					a++;
					break;
				case 'b':
					b++;
					break;
				case 'c':
					c++;
					break;
			}
			if(spr(a,b,c))
				ans++;
		}
	}
	cout << ans;
	return 0;
}