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
// v10_
#include <iostream>
using namespace std;

int main() {
  string slowo;
  unsigned long long int x = 0;
  unsigned int a;
  unsigned int b;
  unsigned int c;

  cin >> slowo;
  int dl = int(slowo.size());

  for (int i = 0; i < dl; ++i) {
    a = 0;
    b = 0;
    c = 0;
    for (int j = i; j < dl; ++j) {
      if (slowo[j] == 'a') {
        a++;
      } else if (slowo[j] == 'b') {
        b++;
      } else {
        c++;
      }
      if ((a == b && b == c) || ((a == 0 || b == 0 || c == 0) && (a == b || b == c || a == c))) {
        x++;
      }
    }
  }
  cout << x << "\n";
}