#include <bits/stdc++.h>
#include <iostream>
#include <functional>
#include <vector>
#include <stdio.h>
#include <queue>
#include <string.h>
#include <math.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define rep1(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
#define per1(i,a,n) for (int i=a;i>n;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define endl "\n"
#define pi 3.14159265358979323846264338327950288419716939937510
#define IOS cin.sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll mod=1000000007;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
ll qpow(ll a,ll b){ll s=1;while(b>0){if(b%2==1){s=s*a;}a=a*a;b=b>>1;}return s;}
ll qpowmod(ll a, ll b, ll c){ll res, t;res=1;t=a%c;while(b){if(b & 1){res=res*t%c;}t=t*t%c;b>>=1;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline long long read(){long long k=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}return k*f;}
inline void write(long long x){if(x<0)x=-x,putchar('-');if(x>9)write(x/10);putchar(x%10+'0');}
// head
ll n,ans,cnt,a[3][4005];
char s[4005];
int main()
{
    //IOS;
    cin>>n>>s;
    for(int i=n-1;i>=0;i--)
    {
        a[0][i]=a[0][i+1];
        a[1][i]=a[1][i+1];
        a[2][i]=a[2][i+1];
        if(s[i]=='R')
        {
            a[0][i]++;
        }
        else if(s[i]=='G')
        {
            a[1][i]++;
        }
        else if(s[i]=='B')
        {
            a[2][i]++;
        }
    }
    /*for(int i=0; i<=n-1; i++)
    {
        cout<<a[0][i]<<' ';
    }
    cout<<endl;
    for(int i=0; i<=n-1; i++)
    {
        cout<<a[1][i]<<' ';
    }
    cout<<endl;
    for(int i=0; i<=n-1; i++)
    {
        cout<<a[2][i]<<' ';
    }
    cout<<endl;*/
    for(int i=0; i<=n-1; i++)
    {
        for(int j=i+1; j<=n-1; j++)
        {
            if(s[i]=='R'&&s[j]=='G')
            {
                ans+=a[2][j];
                if(s[2*j-i]=='B'&&j<(2*j-i)&&(2*j-i)<=n-1)
                {
                    ans--;
                }
            }
            else if(s[i]=='G'&&s[j]=='R')
            {
                ans+=a[2][j];
                if(s[2*j-i]=='B'&&j<(2*j-i)&&(2*j-i)<=n-1)
                {
                    ans--;
                }
            }
            else if(s[i]=='G'&&s[j]=='B')
            {
                ans+=a[0][j];
                if(s[2*j-i]=='R'&&j<(2*j-i)&&(2*j-i)<=n-1)
                {
                    ans--;
                }
            }
            else if(s[i]=='B'&&s[j]=='G')
            {
                ans+=a[0][j];
                if(s[2*j-i]=='R'&&j<(2*j-i)&&(2*j-i)<=n-1)
                {
                    ans--;
                }
            }
            else if(s[i]=='R'&&s[j]=='B')
            {
                ans+=a[1][j];
                if(s[2*j-i]=='G'&&j<(2*j-i)&&(2*j-i)<=n-1)
                {
                    ans--;
                }
            }
            else if(s[i]=='B'&&s[j]=='R')
            {
                ans+=a[1][j];
                if(s[2*j-i]=='G'&&j<(2*j-i)&&(2*j-i)<=n-1)
                {
                    ans--;
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}
/*

*/




Measured memory_bytes: 3660