///////////////////////////////////////////
//                                       //
//      Gagan_Sharma : DTU               // 
//                                       //                   
///////////////////////////////////////////
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int     long long
// #define mp      make_pair
#define eb      emplace_back
#define pb      push_back
#define ss      second
#define ff      first
#define IOS     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod     998244353
#define MOD     (1000*1000*1000+7)
#define MN      LLONG_MIN
#define MX      LLONG_MAX
#define v1d     vector<int>
#define v2d     vector<vector<int>>
#define vip     vector<pair<int,int> >
#define v1s     vector<string>
#define pa      pair<int,int>
#define print(v) for(auto i:v)cout<<i<<" ";cout<<"\n";
#define endl    '\n'
#define input(b,n) for(int i=0;i<n;i++)cin>>b[i+1];
#define Sort(v) sort(v.begin(),v.end())
#define RSort(v)   sort(v.rbegin(),v.rend())
#define all(v)  v.begin(),v.end()
#define mxpq priority_queue <int>
#define mnpq priority_queue<int,vector<int>,greater<int>>
int gcd(int a,int b){return b?gcd(b,a%b):a;}
//string s = bitset<64>(a).to_string();

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define fbo find_by_order // iterator to the kth element
#define ook order_of_key  //number of items that are strictly smaller than our item k
#define T pair<int,pa>
// #define ordered_set tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>

void read(int n=12){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout<<setprecision(n)<<fixed;
    #ifndef ONLINE_JUDGE
         freopen("input.txt",  "r",  stdin);
         freopen("output.txt", "w", stdout);
    #endif
}

void solve(){
    int n;cin>>n;
    string s;cin>>s;
    s = '#'+s;
    v1d dpr(n+2,0),dpg(n+2,0),dpb(n+2,0);
    for(int i=n;i>=1;i--){
        if(s[i] == 'R')dpr[i]++;
        if(s[i] == 'G')dpg[i]++;
        if(s[i] == 'B')dpb[i]++;
        dpr[i] += dpr[i+1];
        dpg[i] += dpg[i+1];
        dpb[i] += dpb[i+1];
    }
    int sum = 0;
    for(int i=1;i<=n-3;i++){
        if(s[i] == 'R'){
            for(int j=i+1;j<=n;j++){
                if(s[j] == 'G'){
                    sum += dpb[j+1];
                    if(j+j-i <=n && s[j+j-i] == 'B')sum--;
                }
                else if(s[j] == 'B'){
                    sum += dpg[j+1];
                    if(j+j-i <=n && s[j+j-i] == 'G')sum--;
                }
            }
        }
        else if(s[i] == 'G'){
            for(int j=i+1;j<=n;j++){
                if(s[j] == 'R'){
                    sum += dpb[j+1];
                    if(j+j-i <=n && s[j+j-i] == 'B')sum--;
                }
                else if(s[j] == 'B'){
                    sum += dpr[j+1];
                    if(j+j-i <=n && s[j+j-i] == 'R')sum--;
                }
            }
        }
        if(s[i] == 'B'){
            for(int j=i+1;j<=n;j++){
                if(s[j] == 'G'){
                    sum += dpr[j+1];
                    if(j+j-i <=n && s[j+j-i] == 'R')sum--;
                }
                else if(s[j] == 'R'){
                    sum += dpg[j+1];
                    if(j+j-i <=n && s[j+j-i] == 'G')sum--;
                }
            }
        }
    }

    cout<<sum;


}
 
int32_t main(){
    read();
    int t = 1;
    // cin>>t;
    while(t--){
        solve();
    }
    


    return 0;
}                                                                                         

Measured memory_bytes: 3748