//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
//#pragma GCC target ("avx,avx2,tune=native")
//#pragma GCC optimization ("unroll-loops")
#include "bits/stdc++.h"

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/rope>

using namespace __gnu_pbds; 
using namespace __gnu_cxx;
using namespace std;
using ll = long long;

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(v) ((int)v.size())
#define all(v) v.begin(), v.end()
#define precision(n) fixed<<setprecision(n)

#ifdef LOCAL
    #include "debug.h"
#else
    #define debug(...) 42
#endif

void io(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);    
    #ifdef LOCAL
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        freopen("output.txt","w",stderr);
    #endif
}
template<typename T> using oset = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update >;
template<typename T> using MinPriorityQueue = priority_queue <T, vector <T>, greater <T> >;
template<typename T> void done(T ans) {cout << ans << "\n"; exit(0);}

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937_64 mt(seed);

clock_t time_p=clock();
void printTime(){
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
  for(auto& i:x)
    input>>i;
  return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
  for(auto& i:x)
    output<<i<<' ';
  return output;
}


const int N = 2e5 + 5;

int main() {
    io();
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> v[3];
    for(int i = 0; i < n; i++) {
        if(s[i] == 'R') {
            v[0].push_back(i);
        }
        else if(s[i] == 'G') {
            v[1].push_back(i);
        }
        else {
            v[2].push_back(i);
        }
    }
    ll sum = 0;

    for(int i = 0; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
            if(s[i] != s[j]) {
                int k = j + (j - i);
                if(s[i] == 'R' and s[j] == 'G') {
                    sum += (v[2].size() - (lower_bound(v[2].begin(), v[2].end(), j) - v[2].begin()));
            
                    if(k < (int)s.size() and s[k] == 'B') {
                        sum -= 1;
                    }
                }
                if(s[i] == 'G' and s[j] == 'R') {
                    sum += (v[2].size() - (lower_bound(v[2].begin(), v[2].end(), j) - v[2].begin()));
            
                    if(k < (int)s.size() and s[k] == 'B') {
                        sum -= 1;
                    }
                }
                if(s[i] == 'R' and s[j] == 'B') {
                    sum += (v[1].size() - (lower_bound(v[1].begin(), v[1].end(), j) - v[1].begin()));
            
                    if(k < (int)s.size() and s[k] == 'G') {
                        sum -= 1;
                    }
                }
                if(s[i] == 'B' and s[j] == 'R') {
                    sum += (v[1].size() - (lower_bound(v[1].begin(), v[1].end(), j) - v[1].begin()));
            
                    if(k < (int)s.size() and s[k] == 'G') {
                        sum -= 1;
                    }
                }
                if(s[i] == 'B' and s[j] == 'G') {
                    sum += (v[0].size() - (lower_bound(v[0].begin(), v[0].end(), j) - v[0].begin()));
            
                    if(k < (int)s.size() and s[k] == 'R') {
                        sum -= 1;
                    }
                }
                if(s[i] == 'G' and s[j] == 'B') {
                    sum += (v[0].size() - (lower_bound(v[0].begin(), v[0].end(), j) - v[0].begin()));
                    if(k < (int)s.size() and s[k] == 'R') {
                        sum -= 1;
                    }
                }
            }
        }
    }
    // for(int i = 0; i < (int)v[0].size(); i++) {
    //     for(int j = 0; j < (int)v[1].size(); j++) {
    //         int k = abs(v[1][j] - v[0][i]);
    //         int id = k + max(v[1][j], v[0][i]);
    //         int id2 = k + abs(v[1][j] - v[0][i]);
    //         sum += (v[2].size() - (lower_bound(v[2].begin(), v[2].end(), id - k) - v[2].begin()));
            
    //         if(id < (int)s.size() and s[id] == 'B') {
    //             sum -= 1;
    //         }

    //     }
    // }
    // for(int i = 0; i < (int)v[0].size(); i++) {
    //     for(int j = 0; j < (int)v[2].size(); j++) {
    //         int k = abs(v[2][j] - v[0][i]);
    //         int id = k + max(v[2][j], v[0][i]);
    //         sum += (v[1].size() - (lower_bound(v[1].begin(), v[1].end(), id - k) - v[1].begin()));

    //         if(id < (int)s.size() and s[id] == 'G') {
    //             sum --;
    //         }            
    //   }
    // }

    // for(int i = 0; i < (int)v[1].size(); i++) {
    //     for(int j = 0; j < (int)v[2].size(); j++) {
    //         int k = abs(v[1][j] - v[2][i]);
    //         int id = k + max(v[1][j], v[2][i]);
    //         sum += (v[0].size() - (lower_bound(v[0].begin(), v[0].end(), id - k) - v[0].begin()));

    //         if(id < (int)s.size() and s[id] == 'R') {
    //             sum--;
    //         }
    //     }
    // }
    cout << sum;
}





Measured memory_bytes: 3648