#include<bits/stdc++.h>
#define f first
#define se second
#define pb push_back
#define pf push_front
#define eb emplace_back
#define emp emplace
#define ins insert
#define sz(s) (int)s.size()
#define rep(i,a,b) for( int i=a;i<b;i++)
#define repr(i,a,b) for( int i=a;i>=b;i--)
#define bitcount __builtin_popcount
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mem(n,m) memset(n,m,sizeof(n))
#define ii pair<int,int>
#define iii tuple<int, int, int>
#define si set<int>
#define vi vector<int>
#define vii vector<ii>
#define mi map<int,int>
#define lb lower_bound
#define ub upper_bound
#define present(s,x) (s.find(x) != s.end())
#define ford(container, it) for(auto it:container)
#define fors(container, it, a, b) for(auto it = a; it != b; it++)
#define Anurag_Gupta ios_base::sync_with_stdio(0);
#define IIIT_ALLD cin.tie(0);cout.tie(0);
#define mod 987654319
#define EPSILON 1e-9
#define PI acos(-1)
#define inf 1e17
#define int long long
#define debug(a) cerr<<#a<<": ";for(auto i:a)cerr<<i<<" ";cerr<<'\n';
#define trace(a) cerr<<#a<<": "<<a<<"\n"
#define gcd(a,b) __gcd(a,b)
using namespace std;
int add(int a, int b, int c){int res=a+b;return(res>=c?res-c:res);}
int mod_neg(int a, int b, int c){int res;if(abs(a-b)<c)res=a-b;else res=(a-b)%c;return(res<0?res+c:res);}
int mul(int a, int b, int c){int res=(int)a*b;return(res>=c?res%c:res);}
template<typename T>T power(T e, T n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
template<typename T>T mdpower(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mul(x,p,m);p=mul(p,p,m);n>>=1;}return x;}
template<typename T>T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;\
t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
template<typename T>T mod_inverse(T a, T n){T x,y,z=0;T d=extended_euclid(a,n,x,y);return(d>1?-1:mod_neg(x,z,n));}
/*------------------------------------------------------------------------------------------------------------------*/

int32_t main()
{
    Anurag_Gupta
    IIIT_ALLD
 
  
  
    
    int n;
    cin>>n;

    string s;cin>>s;

    map<char,int>pref[n];
    map<char,int>suff[n];
    int ans=0;


    for(int i=0;i<n;i++)
    {
        char x = s[i];

        if(i>0)
        for(auto it:pref[i-1])
        pref[i][it.f] += it.se;

        pref[i][x]++;

    }

    for(int i = n-1;i>=0;i--)
    {
        if(i<n-1)
        for(auto it:suff[i+1])
        {
            suff[i][it.f] += it.se;
        }

        suff[i][s[i]]++;

    }

    for(int i=1;i<n-1;i++)
    {
        if(s[i]=='R')
        {
            ans = ans+pref[i-1]['G']*suff[i+1]['B'];
            ans+=pref[i-1]['B']*suff[i+1]['G'];
        }
        else if(s[i]=='G')
        {
             ans = ans+pref[i-1]['R']*suff[i+1]['B'];
            ans+=pref[i-1]['B']*suff[i+1]['R'];
        }
        else
        {
            ans = ans+pref[i-1]['R']*suff[i+1]['G'];
            ans+=pref[i-1]['G']*suff[i+1]['R'];
        }

        for(int j = 1;j<=min(i,n-i-1);j++)
        {
            char a = s[i-j];
            char b = s[i+j];
            if(a!=s[i] and b!=s[i] and a!=b){
                //cout<<i<<" "<<j<<"\n";
            ans--;
            }
        }
    
    }

    cout<<ans<<'\n';
 






 
#ifndef LOCAL_DEFINE
        cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
}


Measured memory_bytes: 5660