/**
 *    Author:   Jay Sabale
 *	       
**/

#include<bits/stdc++.h>

using namespace std;
 
// Competetive Template:
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;
typedef vector <lli> vl;
typedef vector <string> vs;
typedef vector < pair <long, long> > vll;

// Debugging :
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ba  back
#define si size()
#define be begin()
#define en end()
#define le length()
#define mp make_pair 
#define mt make_tuple
#define fi first
#define se second
#define gcd __gcd
#define maxe *max_element
#define mine *min_element
#define deb debug
 
#define forz(i,n) for(lli i=0; i<n; i++)
#define rep(i,k,n) for (lli i = k; i < n; i++)
#define deci(n)  fixed<<setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n)  __builtin_ctz(n)
#define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0),cout.tie(0)

// Printing Data :
#define pvec(v) forz(i,v.si) cout<<v[i]<<" "; cout<<endl;
#define parr(arr, n) forz(i,n) cout<<arr[i]<<" "; cout<<endl;
#define p1(i) cout<<i<<endl;
#define p2(i, j) cout<<i<<" "<<j<<endl;
#define p3(i, j, k) cout<<i<<" "<<j<<" "<<k<<endl;
#define p4(i, j, k, l) cout<<i<<" "<<j<<" "<<k<<" "<<l<<endl;

typedef pair <lli,lli> pll;
// Finds number of elements greater than k in a vector . O(lg n)
lli countGreater(vector <lli> &v, lli k) 
{ 
    lli l = 0; 
    lli r = v.si - 1; 
  
    lli leftGreater = v.si; 
  
    while (l <= r) { 
        lli m = l + (r - l) / 2; 
  
        if (v[m] > k) { 
            leftGreater = m; 
            r = m - 1; 
        } 
  
        else
            l = m + 1; 
    } 
  
    return (v.si - leftGreater); 
} 

void solve()
{
    lli n; cin>>n;
    string s; cin>>s;

    vector <lli> v1, v2, v3;

    forz(i, s.le)
    {
        if(s[i] == 'R') v1.pb(i);
        if(s[i] == 'G') v2.pb(i);
        if(s[i] == 'B') v3.pb(i);
    }

    lli res = 0;

    forz(i, s.le)
    {
        for(lli j=i+1; j<s.le; j++)
        {
            if(s[i] != s[j])
            {
                if(s[i]=='R' && s[j]=='G' || s[i]=='G' && s[j]=='R')
                {
                    lli te = countGreater(v3, j);
                    lli diff = j - i;

                    res += te;

                    if(j+diff < s.le && s[j+diff] == 'B')
                    res--;
                }

                if(s[i]=='G' && s[j]=='B' || s[i]=='B' && s[j]=='G')
                {
                    lli te = countGreater(v1, j);
                    lli diff = j - i;

                    res += te;

                    if(j+diff < s.le && s[j+diff] == 'R')
                    res--;
                }

                if(s[i]=='B' && s[j]=='R' || s[i]=='R' && s[j]=='B')
                {
                    lli te = countGreater(v2, j);
                    lli diff = j - i;

                    res += te;

                    if(j+diff < s.le && s[j+diff] == 'G')
                    res--;
                }
            }
        }
    }
    
    cout<<res<<endl;
}

string genstring(lli n)
{
    srand(time(0));
    string s;
    forz(i, n)
    {
        lli t = rand()%3;

        if(t==0) s.pb('R');
        else if(t==1) s.pb('G');
        else s.pb('B');
    }

    return s;
}
 
// CODE BEGINS :

int main()
{
    kira; 

    solve();

    return 0;
}




















































Measured memory_bytes: 3640