#include<bits/stdc++.h>
#define int long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define PI acos(-1)
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define sp fixed<<setprecision
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int MOD = (1e9)+7;
const int N = (1e6)+5;

signed main()
{
    FAST
    int tc=1;
    //cin>>tc;
    for(int ti=1;ti<=tc;ti++)
    {
        int n;
        cin>>n;
        string s;
        cin>>s;
        int cnt[3][n];
        memset(cnt,0,sizeof(cnt));
        map<char,int> mp;
        mp['R'] = 0;
        mp['G'] = 1;
        mp['B'] = 2;
        for(int i=n-1;i>=0;i--)cnt[mp[s[i]]][i]++;
        for(int i=0;i<3;i++)
        {
            for(int j=n-2;j>=0;j--)cnt[i][j]+=cnt[i][j+1];
        }
        int ans = 0;
        for(int i=0;i<n;i++)
        {
            for(int j=i+1;j<n;j++)
            {
                if(s[i]==s[j])continue;
                int k = j+(j-i);
                int col = -1;
                int chk = mp[s[i]]^mp[s[j]];
                if(chk == 1)col = 2;
                else if(chk == 2)col = 1;
                else col = 0;
                if(j+1<n)ans+=cnt[col][j+1];
                if(k<n && mp[s[k]] == col)ans--;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}
/*
Test Case
*/
