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
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

int main() {
  int a = 0;
  string y;
  cin >> y;
  for (int i = 0; i < y.size(); i++) {
    for (int j = i; j < y.size(); j++) {
      int l = j - i + 1;
      if (l < 3) { a++; continue; };
      string s = y.substr(i, l);
      set<char> o(s.begin(), s.end());
      vector<int> b;
      if (o.size() == 1) { a++; continue; };
      for (auto x : o) b.push_back(count(s.begin(), s.end(), x));
      if (b.size() == 2 && b[0] == b[1]) a++;
      if (b.size() == 3 && b[0] == b[1] && b[1] == b[2]) a++;
    };
  };
  cout << a;
  return 0;
};