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
#include <cstdio>
#include <unordered_map>
using namespace std;

const int MAGIC_CONSTANT = 323232;
char magicBuf[MAGIC_CONSTANT];
long long magicArray[7][128];

int main() {
	// ABC
	magicArray[0]['a'] = 1;
	magicArray[0]['b'] = 0 - MAGIC_CONSTANT - 1;
	magicArray[0]['c'] = MAGIC_CONSTANT;
	// AB
	magicArray[1]['a'] = 1;
	magicArray[1]['b'] = 0 - 1;
	magicArray[1]['c'] = MAGIC_CONSTANT;
	// BC
	magicArray[2]['a'] = MAGIC_CONSTANT;
	magicArray[2]['b'] = 1;
	magicArray[2]['c'] = 0 - 1;
	// CA
	magicArray[3]['a'] = 1;
	magicArray[3]['b'] = MAGIC_CONSTANT;
	magicArray[3]['c'] = 0 - 1;
	// A
	magicArray[4]['a'] = 0;
	magicArray[4]['b'] = 1;
	magicArray[4]['c'] = 1;
	// B
	magicArray[5]['a'] = 1;
	magicArray[5]['b'] = 0;
	magicArray[5]['c'] = 1;
	// C
	magicArray[6]['a'] = 1;
	magicArray[6]['b'] = 1;
	magicArray[6]['c'] = 0;


	char *magicWord = magicBuf;
	scanf("%s", magicWord);

	long long magicValue[7];
	unordered_map<long long, int> magicMap[7];
	for (int i = 0; i < 7; ++i) {
		magicValue[i] = 0;
		++magicMap[i][magicValue[i]];
	}

	long long fullyRealResult = 0;

	while (*magicWord) {
		for (int i = 0; i < 7; ++i) {
			magicValue[i] += magicArray[i][*magicWord];
			fullyRealResult += magicMap[i][magicValue[i]];
			++magicMap[i][magicValue[i]];
		}
		++magicWord;
	}

	printf("%lld\n", fullyRealResult);

	return 0;
}