#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S,False(1,-1);
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}

template<typename A,size_t N,typename T>
void Fill(A(&array)[N],const T &val){
    fill((T*)array,(T*)(array+N),val);
}

ll gcd(ll a,ll b){
    if(a%b==0)return b;
    else return gcd(b,a%b);
}


int solve( int x ){
    if( x == 0 )return 1;
    if( x < 0 )return 0;

    rep(i,6){
        return solve( x - 100 - i );
    }
}

int dp[ 100000 ];
int main(){
    int n;
    string s;
    cin >> n >> s;

    vector<int> r(n) ,g(n) ,b(n);
    rep(i , n){
        if( s[i] == 'R' )r[i]++;
        if( s[i] == 'G' )g[i]++;
        if( s[i] == 'B' )b[i]++;

        if( i != 0 )r[i] += r[i-1];
        if( i != 0 )g[i] += g[i-1];
        if( i != 0 )b[i] += b[i-1];
    }


    ll res = 0;
    rep(i , n){
        for(int j = i+1; j < n; j++){
            if( s[i] == s[j] )continue;

            if( s[i] != 'R' && s[j] != 'R' ){
                
                if( 2 * j - i >= n){
                    res += r[n-1] - r[j];
                }

                else {
                    res += r[2*j-i-1] - r[j] + r[n-1] - r[2*j-i];
                }

            }

            if( s[i] != 'G' && s[j] != 'G' ){
                
                if( 2 * j - i >= n){
                    res += g[n-1] - g[j];
                }

                else {
                    res += g[2*j-i-1] - g[j] + g[n-1] - g[2*j-i];
                }
                
            }

            if( s[i] != 'B' && s[j] != 'B' ){
                
                if( 2 * j - i >= n){
                    res += b[n-1] - b[j];
                }

                else {
                    res += b[2*j-i-1] - b[j] + b[n-1] - b[2*j-i];
                }
                
            }

            //cout << res << endl;
        }
    }

    cout << res << endl;
}