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
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
string s;
vector<char> incl;
long long solve(size_t bg=0)
{
	map<vector<int>,int> mp;
	vector<int> p(incl.size()-1);
	mp[p]=1;
	long long ans=0;
	size_t it;
	for(it=bg;it<s.size();it++)
	{
		char v=s[it];
		if(incl[0]==v)
		{
			for(auto &v2:p)
				v2--;
		}
		else
		{
			size_t i;
			for(i=1;i<incl.size();i++)
			{
				if(incl[i]==v)
				{
					p[i-1]++;
					break;
				}
			}
			if(i==incl.size())
				return ans+solve(it+1);
		}
		ans+=mp[p];
		mp[p]++;
	}
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	long long ans=0;
	char cc[3]={'a','b','c'};
	cin>>s;
	for(int i=1;i<8;i++)
	{
		incl.clear();
		for(int j=0;j<3;j++)
		{
			if(i&(1<<j))
				incl.push_back(cc[j]);
		}
		ans+=solve();
		//cerr<<i<<" "<<incl.size()<<" "<<ans<<"\n";
	}
	cout<<ans<<"\n";
	return 0;
}