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
#include <iostream>
#include <string>
using namespace std;
int charcount(string s, char c)
{
if (s.find(c) < 0)
return 0;
int ret = 0;
for (int i=0; i<s.size(); i++)
if (s[i] == c)
ret++;
return ret;
}

int zba(string s)
{
int a,b,c, ret = 0 ;
string sub;
for (int i=0; i<s.size(); i++)
{
for (int j=1; j<=s.size()-i; j++)
{
sub = s.substr(i,j);
a = charcount(sub, 'a');
b = charcount(sub, 'b');
c = charcount(sub, 'c');

if (a > 0)
{
if ((b > 0 && b == a) || b == 0)
if ((c > 0 && c == a) || c == 0)
ret++;
}
else if ((b > 0 && c == 0) || (b == 0 && c > 0) || (b > 0 && b == c))
ret++;
}
}
return ret;
}

int main()
{
int res = 0;
string inp;
getline(cin, inp);
cout << zba(inp);
return 0;
}