Language: C++

#include <iostream>
#include <map>

int countAligned(const std::map<char, std::set<int>> &char2pos,
                 const char a, const char b, const char c) {
  int ans = 0;
  for (int i : char2pos[a]) {
    for (int j : char2pos[b]) {
      if ((i + j) & 1 != 0) {
        continue;
      }
      int k = (i + j) >> 1;
      if (char2pos[c].find(k) != char2pos[c].end()) {
        ans += 1;
      }
    }
  }
  return ans;
}

int main() {
  int len, std::string s;
  std::cin >> len;
  std::cin >> s;
  std::map<char, std::set<int>> char2pos;
  for (int pos = 0; pos < s.size(); pos++) {
    char2pos[s[pos]].push_back(pos);
  }
  int ans = char2pos['R'].size() * char2pos['G'].size() * char2pos['B'].size();
  ans -= countAligned(char2pos, 'R', 'G', 'B');
  ans -= countAligned(char2pos, 'R', 'B', 'G');
  ans -= countAligned(char2pos, 'G', 'B', 'R');
  return ans;
}

Compiler output:
a.cc:4:44: error: 'set' is not a member of 'std'
    4 | int countAligned(const std::map<char, std::set<int>> &char2pos,
      |                                            ^~~
a.cc:3:1: note: 'std::set' is defined in header '<set>'; this is probably fixable by adding '#include <set>'
    2 | #include <map>
  +++ |+#include <set>
    3 | 
a.cc:4:51: error: template argument 2 is invalid
    4 | int countAligned(const std::map<char, std::set<int>> &char2pos,
      |                                                   ^~
a.cc:4:51: error: template argument 4 is invalid
a.cc:4:44: error: 'set' is not a member of 'std'
    4 | int countAligned(const std::map<char, std::set<int>> &char2pos,
      |                                            ^~~
a.cc:4:44: note: 'std::set' is defined in header '<set>'; this is probably fixable by adding '#include <set>'
a.cc:4:51: error: template argument 2 is invalid
    4 | int countAligned(const std::map<char, std::set<int>> &char2pos,
      |                                                   ^~
a.cc:4:51: error: template argument 4 is invalid
a.cc:4:44: error: 'set' is not a member of 'std'
    4 | int countAligned(const std::map<char, std::set<int>> &char2pos,
      |                                            ^~~
a.cc:4:44: note: 'std::set' is defined in header '<set>'; this is probably fixable by adding '#include <set>'
a.cc:4:51: error: template argument 2 is invalid
    4 | int countAligned(const std::map<char, std::set<int>> &char2pos,
      |                                                   ^~
a.cc:4:51: error: template argument 4 is invalid
a.cc:4:24: error: invalid template-id
    4 | int countAligned(const std::map<char, std::set<int>> &char2pos,
      |                        ^~~
a.cc:4:44: error: 'set' is not a member of 'std'
    4 | int countAligned(const std::map<char, std::set<int>> &char2pos,
      |                                            ^~~
a.cc:4:44: note: 'std::set' is defined in header '<set>'; this is probably fixable by adding '#include <set>'
a.cc:4:18: error: expected primary-expression before 'const'
    4 | int countAligned(const std::map<char, std::set<int>> &char2pos,
      |                  ^~~~~
a.cc:5:18: error: expected primary-expression before 'const'
    5 |                  const char a, const char b, const char c) {
      |                  ^~~~~
a.cc:5:32: error: expected primary-expression before 'const'
    5 |                  const char a, const char b, const char c) {
      |                                ^~~~~
a.cc:5:46: error: expected primary-expression before 'const'
    5 |                  const char a, const char b, const char c) {
      |                                              ^~~~~
a.cc:5:58: error: expression list treated as compound expression in initializer [-fpermissive]
    5 |                  const char a, const char b, const char c) {
      |                                                          ^
a.cc: In function 'int main()':
a.cc:22:24: error: qualified-id in declaration before 's'
   22 |   int len, std::string s;
      |                        ^
a.cc:24:15: error: 's' was not declared in this scope
   24 |   std::cin >> s;
      |               ^
a.cc:25:23: error: 'set' is not a member of 'std'
   25 |   std::map<char, std::set<int>> char2pos;
      |                       ^~~
a.cc:25:23: note: 'std::set' is defined in header '<set>'; this is probably fixable by adding '#include <set>'
a.cc:25:30: error: template argument 2 is invalid
   25 |   std::map<char, std::set<int>> char2pos;
      |                              ^~
a.cc:25:30: error: template argument 4 is invalid
a.cc:29:21: error: invalid types 'int[char]' for array subscript
   29 |   int ans = char2pos['R'].size() * char2pos['G'].size() * char2pos['B'].size();
      |                     ^
a.cc:29:44: error: invalid types 'int[char]' for array subscript
   29 |   int ans = char2pos['R'].size() * char2pos['G'].size() * char2pos['B'].size();
      |                                            ^
a.cc:29:67: error: invalid types 'int[char]' for array subscript
   29 |   int ans = char2pos['R'].size() * char2pos['G'].size() * char2pos['B'].size();
      |                                                                   ^
a.cc:30:22: error: 'countAligned' cannot be used as a function
   30 |   ans -= countAligned(char2pos, 'R', 'G', 'B');
      |          ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:31:22: error: 'countAligned' cannot be used as a function
   31 |   ans -= countAligned(char2pos, 'R', 'B', 'G');
      |          ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:32:22: error: 'countAligned' cannot be used as a function
   32 |   ans -= countAligned(char2pos, 'G', 'B', 'R');
      |          ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~