// Author: Mrigank
// Science is what we understand well enough to explain to a computer, Art is everything else we do - Donald E. Knuth
#include <bits/stdc++.h>
#include <iostream>
#include <unordered_map>
#include <map>
#include <queue>
#include <stack>
#include <unordered_set>
#include <set>
#include <string> 
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<ll, int> PLI;
typedef pair<int, int> PII;
typedef vector < ll > vl;
typedef vector < int > vi;
typedef vector < bool > vb;
typedef vector < pair < ll , ll > > vpl;
typedef vector < pair < ll , bool > > vpb;
typedef vector < vector < int > > vvi;
typedef vector < vector < ll > > vvl;


#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;i<n;i++)
#define pi pair < ll , ll >
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define clr(x , val) memset(x , val , sizeof(x))
#define deb1(x) cout << x << endl
#define deb2(x , y) cout << x << " " << y << endl
#define deb3(x , y , z) cout << x << " " << y << " " << z << endl
#define all(x) x.begin() , x.end()
#define alls(x , y) x.begin() , x.end() , y
#define fastIO                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);


const ll mxsize = 5e6 + 5;
const ll linf = 1e9;
const ld inf = 10000000000.0;
const ll mod = 1e9 + 7;
 
/******************************************** CODE STARTS FROM HERE *************************************************/ 

int main()
{
    fastIO;
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll i , j;
    unordered_map < ll , unordered_map < char , ll > >  mp;
    fo(i , n)
    {
        Fo(j , i + 1 , n)
        {
            mp[i][s[j]]++;
        }
    }
    ll ans = 0;
    fo(i , n - 2)
    {
        Fo(j , i + 1 , n - 1)
        {
            if(s[i] == s[j]) continue;
            else
            {
                char a = s[i];
                char b = s[j];
                if(a == 'R' && b == 'G')
                {
                    ans += mp[j]['B'];
                }
                else if(a == 'R' && b == 'B')
                {
                    ans += mp[j]['G'];
                }
                else if(a == 'B' && b == 'G')
                {
                    ans += mp[j]['R'];
                }
                else if(a == 'B' && b == 'R')
                {
                    ans += mp[j]['G'];
                }
                else if(a == 'G' && b == 'R')
                {
                    ans += mp[j]['B'];
                }
                else if(a == 'G' && b == 'B')
                {
                    ans += mp[j]['R'];
                }
            }
        }
    }
    fo(i , n - 2)
    {
        Fo(j , i + 1 , n - 1)
        {
            ll k = 2 * j - i;
            if(k >= n) continue;
            if(s[i] != s[j])
            {
                if(s[i] != s[k] && s[j] != s[k]) ans--;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4488