#include <bits/stdc++.h>

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
//    cout << fixed << setprecision(15);

    string s,t;
    i32 n,m,p,q,r;
    cin >> n >> s;
    vi csumR(n+1); rep(i,n) csumR[i+1] += csumR[i] + (s[i]=='R' ? 1 : 0);
    vi csumG(n+1); rep(i,n) csumG[i+1] += csumG[i] + (s[i]=='G' ? 1 : 0);
    vi csumB(n+1); rep(i,n) csumB[i+1] += csumB[i] + (s[i]=='B' ? 1 : 0);

//    debug => ok
//    for(auto i : csumR) cout << i << ' ';
//    cout << '\n';    for(auto i : csumG) cout << i << ' ';
//    cout << '\n';    for(auto i : csumB) cout << i << ' ';
//    cout << '\n';

    i32 cnt = 0;
    for(i32 i = 0; i < n-2; ++i) {
        for(i32 j = i+1; j < n-1; ++j) {
            if(s[i]==s[j]) continue;
//            cout << s[i] << ' ' << s[j] << '\n';  // debug

            char chh1 = min(s[i], s[j]);
            char chh2 = max(s[i], s[j]);
//            cout << chh1 << ' ' << chh2 << '\n';  // debug


            if(chh1 == 'G' && chh2 == 'R') {
                cnt += csumB[n] - csumB[j+1];
                if(j+j-i < n) cnt -= (s[j+j-i]=='B' ? 1 : 0);
            }
            else if(chh1 == 'B' && chh2 == 'G') {
                cnt += csumR[n] - csumR[j+1];
                if(j+j-i < n) cnt -= (s[j+j-i]=='R' ? 1 : 0);
            }
            else if(chh1 == 'B' && chh2 == 'R') {
                cnt += csumG[n] - csumG[j+1];
                if(j+j-i < n) cnt -= (s[j+j-i]=='G' ? 1 : 0);
            }
//            else cout << "!" << '\n';  // debug
//            debug(cnt);
        }
    }

    /**
     * WA * 4 .. large case
     */
    cout <<  cnt       << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}
