#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<int>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#include <time.h>
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;


int main(){
    
    int n;
    string s;
    cin >> n >> s;
    vector<int> cR(n,0);vector<int> cG(n,0);vector<int> cB(n,0);
    
    if (s[n-1] == 'R') cR[n-1] = 1;
    if (s[n-1] == 'G') cG[n-1] = 1;
    if (s[n-1] == 'B') cB[n-1] = 1;
    FORR(i,0,n-1){
        cR[i] = cR[i+1]; cB[i] = cB[i+1]; cG[i] = cG[i+1];
        if (s[i] == 'R')cR[i]++; 
        if (s[i] == 'G')cG[i]++;
        if (s[i] == 'B')cB[i]++;
    }

    ll ans = 0LL;
    rep(i,n){
        if (s[i] == 'R'){
            FOR(j,i+1,n){
                int d = j-i;
                if (s[j] == 'G'){
                    int k = min(n-1,j+1);            
                    ans += cB[k];
                    if (j+d > n-1) continue;
                    int del = j+d;
                    if (s[del] == 'B') ans--;
                }
                if (s[j] == 'B'){
                    int k = min(n-1,j+1);            
                    ans += cG[k];
                    if (j+d > n-1) continue;
                    int del = j+d;
                    if (s[del] == 'G') ans--;
                }
            }
        }
        
        if (s[i] == 'G'){
            FOR(j,i+1,n){
                int d = j-i;
                if (s[j] == 'R'){
                    int k = min(n-1,j+1);            
                    ans += cB[k];
                    if (j+d > n-1) continue;
                    int del = j+d;
                    if (s[del] == 'B') ans--;
                }
                if (s[j] == 'B'){
                    int k = min(n-1,j+1);
                    ans += cR[k];
                    int del = min(n-1,j+d);
                    if (j+d > n-1) continue;
                    if (s[del] == 'R') ans--;
                }
            }
        }
        
        if (s[i] == 'B'){
            FOR(j,i+1,n){
                int d = j-i;
                if (s[j] == 'R'){
                    int k = min(n-1,j+1);            
                    ans += cG[k];
                    if (j+d > n-1) continue;
                    int del = j+d;
                    if (s[del] == 'G') ans--;
                }
                if (s[j] == 'G'){
                    int k = min(n-1,j+1);            
                    ans += cR[k];
                    if (j+d > n-1) continue;
                    int del = j+d;
                    if (s[del] == 'R') ans--;
                }
            }
        }
        
    }
    cout << ans;
}











