Language: C++

/**
*    author:  Dooloper
*    created: 12.04.2020 22:03:09
**/

#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>

using namespace std;
typedef unsigned long ll;
   
   
   string S;cin>>S;
   vector< vector<int>> cnt (S.size(),vector<int>(3,0));

ll countPair( char first, char second, char therd, int N){
    ll sum = 0;
    
    for(int i = 0;i < N, i++){
        if(S[i] == first){
            for(int j = i+1; j < N; j++){
                if(S[j] == second){
                    switch (therd)
                    {
                    case 'R':
                        sum += cnt[N-1[0]] - cnt[j + 1 [0]];
                        if(S[j+1] == therd) sum++;
                        if(S[2*j - i] == therd) sum--;
                        break;
                    case 'G':
                        sum += cnt[N-1,1] - cnt[j + 1, 1];
                        if(S[j+1] == therd) sum++;
                        if(S[2*j - i] == therd) sum--;
                        break;
                    case 'B':
                        sum += cnt[N-1,2] - cnt[j + 1, 2];
                        if(S[j+1] == therd) sum++;
                        if(S[2*j - i] == therd) sum--;
                        break;
                    default:
                        break;
                    }
                }
            }
        }
    }
    return sum;
}

int main() {
   cin.tie(0);

   int N;cin>>N;

    if(S[0] == 'R') cnt[i,0]++;
    else if(S[0] == 'G') cnt[i,1]++;
    else cnt[0,2]++;

   for(int i = 1; i < S.size(); i++){
       if(S[i] == 'R') {
           cnt[i,0] = cnt[i-1[0]]++;
           cnt[i,1] = cnt[i-1 [1]];
           cnt[i,2] = cnt[i-1 [2]];
       }
       else if(S[i] == 'G'){
           cnt[i,0] = cnt[i-1 [0]];
           cnt[i,1] = cnt[i-1 [1]]++;
           cnt[i,2] = cnt[i-1 [2]];
       } 
       else {
           cnt[i,0] = cnt[i-1 [0]];
           cnt[i,1] = cnt[i-1 [1]];
           cnt[i,2] = cnt[i-1 [2]]++;
       }
   }

   ll sum = 0;

   sum += countPair('R','G','B',N);
   sum += countPair('R','B','G',N);
   sum += countPair('G','R','B',N);
   sum += countPair('G','B','R',N);
   sum += countPair('B','R','G',N);
   sum += countPair('B','G','R',N);
   
cout<<sum<<endl;


   return 0;
}

Compiler output:
a.cc:17:13: error: 'cin' does not name a type
   17 |    string S;cin>>S;
      |             ^~~
a.cc: In function 'll countPair(char, char, char, int)':
a.cc:23:29: error: expected ';' before ')' token
   23 |     for(int i = 0;i < N, i++){
      |                             ^
      |                             ;
a.cc:30:39: error: invalid types 'int[int]' for array subscript
   30 |                         sum += cnt[N-1[0]] - cnt[j + 1 [0]];
      |                                       ^
a.cc:30:56: error: invalid types 'int[int]' for array subscript
   30 |                         sum += cnt[N-1[0]] - cnt[j + 1 [0]];
      |                                                        ^
a.cc:35:43: error: no match for 'operator-' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} and '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'})
   35 |                         sum += cnt[N-1,1] - cnt[j + 1, 1];
In file included from /usr/include/c++/14/string:48,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:6:
/usr/include/c++/14/bits/stl_iterator.h:618:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__y.base() - __x.base())) std::operator-(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  618 |     operator-(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:618:5: note:   template argument deduction/substitution failed:
a.cc:35:57: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} is not derived from 'const std::reverse_iterator<_Iterator>'
   35 |                         sum += cnt[N-1,1] - cnt[j + 1, 1];
      |                                                         ^
/usr/include/c++/14/bits/stl_iterator.h:1790:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__x.base() - __y.base())) std::operator-(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1790 |     operator-(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1790:5: note:   template argument deduction/substitution failed:
a.cc:35:57: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} is not derived from 'const std::move_iterator<_IteratorL>'
   35 |                         sum += cnt[N-1,1] - cnt[j + 1, 1];
      |                                                         ^
a.cc:40:43: error: no match for 'operator-' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} and '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'})
   40 |                         sum += cnt[N-1,2] - cnt[j + 1, 2];
/usr/include/c++/14/bits/stl_iterator.h:618:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__y.base() - __x.base())) std::operator-(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  618 |     operator-(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:618:5: note:   template argument deduction/substitution failed:
a.cc:40:57: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} is not derived from 'const std::reverse_iterator<_Iterator>'
   40 |                         sum += cnt[N-1,2] - cnt[j + 1, 2];
      |                                                         ^
/usr/include/c++/14/bits/stl_iterator.h:1790:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__x.base() - __y.base())) std::operator-(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1790 |     operator-(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1790:5: note:   template argument deduction/substitution failed:
a.cc:40:57: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} is not derived from 'const std::move_iterator<_IteratorL>'
   40 |                         sum += cnt[N-1,2] - cnt[j + 1, 2];
      |                                                         ^
a.cc: In function 'int main()':
a.cc:59:25: error: 'i' was not declared in this scope
   59 |     if(S[0] == 'R') cnt[i,0]++;
      |                         ^
a.cc:60:30: error: 'i' was not declared in this scope
   60 |     else if(S[0] == 'G') cnt[i,1]++;
      |                              ^
a.cc:61:18: error: no 'operator++(int)' declared for postfix '++' [-fpermissive]
   61 |     else cnt[0,2]++;
a.cc:65:30: error: invalid types 'int[int]' for array subscript
   65 |            cnt[i,0] = cnt[i-1[0]]++;
      |                              ^
a.cc:66:31: error: invalid types 'int[int]' for array subscript
   66 |            cnt[i,1] = cnt[i-1 [1]];
      |                               ^
a.cc:67:31: error: invalid types 'int[int]' for array subscript
   67 |            cnt[i,2] = cnt[i-1 [2]];
      |                               ^
a.cc:70:31: error: invalid types 'int[int]' for array subscript
   70 |            cnt[i,0] = cnt[i-1 [0]];
      |                               ^
a.cc:71:31: error: invalid types 'int[int]' for array subscript
   71 |            cnt[i,1] = cnt[i-1 [1]]++;
      |                               ^
a.cc:72:31: error: invalid types 'int[int]' for array subscript
   72 |            cnt[i,2] = cnt[i-1 [2]];
      |                               ^
a.cc:75:31: error: invalid types 'int[int]' for array subscript
   75 |            cnt[i,0] = cnt[i-1 [0]];
      |                               ^
a.cc:76:31: error: invalid types 'int[int]' for array subscript
   76 |            cnt[i,1] = cnt[i-1 [1]];
      |                               ^
a.cc:77:31: error: invalid types 'int[int]' for array subscript
   77 |            cnt[i,2] = cnt[i-1 [2]]++;
      |                               ^