#include <bits/stdc++.h>
#include <iterator>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <math.h>
#define vi vector<int>
#define vl vector<long long>
#define vpi vector<pair<int,int> >
#define ll long long 
#define vpl vector<pair><long long,long long> > 
#define F first
#define S second
#define mp make_pair
#define ld long double
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pci pair<char,int>
#define un unsigned
# define M_PI           3.14159265358979323846  /* pi */
// #define mod 998244353
#define mod 1000000007
#define MAXN  1000001
using namespace std; 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)


/*
//------------------------------------------DSU--------------------------------------------------------//
int parent[1000001];
int ssize[1000001];


int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

void make_set(int v) {
    parent[v] = v;
    ssize[v] = 1;
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (ssize[a] < ssize[b])
            swap(a, b);
        parent[b] = a;
        ssize[a] += ssize[b];
    }
}
*/

//-----------------------------Sieve Of Eratosthenes--------------------------------------//

/*
v<int> primes;
void SieveOfEratosthenes(int n) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.pb(p); 
}

*/

void solve()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    vector<int> r,g,b;
    for(int i = 0 ; i < n ; i++)
    {
        if(s[i] == 'R')
        {
            r.pb(i);
        }
        if(s[i] == 'G')
        g.pb(i);
        if(s[i] == 'B')
        b.pb(i);
    }
    ll ans = 0;
    vector<int>::iterator it1,it2,it3;
    //  it1 = r.begin();
    //  it2 = g.begin();
    for( it1 = r.begin() ; it1 != r.end() ; it1++)
    {
        for( it2 = upper_bound(g.begin(),g.end(),*it1) ; it2 != g.end() ; it2++)
        {
            int i = min(*it1,*it2);
            int j = max(*it1,*it2);
            int k = 2*(j) - i;
            it3 = upper_bound(b.begin(),b.end(),j);
            // cout<<*it1<<" "<<*it2<<" "<<*it3<<endl;
            // cout<<b.end()-it3<<endl;
            ans += b.end()-it3;
            // cout<<b.end()-it3<<endl;
            if(binary_search(b.begin(),b.end(),k))
            {
                ans--;
            }
            // cout<<ans<<endl;
        }
        for( it2 = upper_bound(b.begin(),b.end(),*it1) ; it2 != b.end() ; it2++)
        {
            int i = min(*it1,*it2);
            int j = max(*it1,*it2);
            int k = 2*(j) - i;
            it3 = upper_bound(g.begin(),g.end(),j);
            ans += g.end()-it3;
            // cout<<g.end()-it3<<endl;
            if(binary_search(g.begin(),g.end(),k))
            {
                ans--;
            }
            // cout<<ans<<endl;
        }
    }
    for( it1 = g.begin() ; it1 != g.end() ; it1++)
    {
        for( it2 = upper_bound(r.begin(),r.end(),*it1) ; it2 != r.end() ; it2++)
        {
            int i = min(*it1,*it2);
            int j = max(*it1,*it2);
            int k = 2*(j) - i;
            it3 = upper_bound(b.begin(),b.end(),j);
            ans += b.end()-it3;
            // cout<<b.end()-it3<<endl;
            if(binary_search(b.begin(),b.end(),k))
            {
                ans--;
            }
            // cout<<ans<<endl;
            
        }
        for( it2 = upper_bound(b.begin(),b.end(),*it1) ; it2 != b.end() ; it2++)
        {
            int i = min(*it1,*it2);
            int j = max(*it1,*it2);
            int k = 2*(j) - i;
            it3 = upper_bound(r.begin(),r.end(),j);
            ans += r.end()-it3;
            // cout<<r.end()-it3<<endl;
            if(binary_search(r.begin(),r.end(),k))
            {
                ans--;
            }
            // cout<<ans<<endl;
        }
    }
    for( it1 = b.begin() ; it1 != b.end() ; it1++)
    {
        for( it2 = upper_bound(g.begin(),g.end(),*it1) ; it2 != g.end() ; it2++)
        {
            int i = min(*it1,*it2);
            int j = max(*it1,*it2);
            int k = 2*(j) - i;
            it3 = upper_bound(r.begin(),r.end(),j);
            ans += r.end()-it3;
            // cout<<r.end()-it3<<endl;
            if(binary_search(r.begin(),r.end(),k))
            {
                ans--;
            }
            // cout<<ans<<endl;
            // int temp = r.end()-it3;
            
        }
        for( it2 = upper_bound(r.begin(),r.end(),*it1) ; it2 != r.end() ; it2++)
        {
            int i = min(*it1,*it2);
            int j = max(*it1,*it2);
            int k = 2*(j) - i;
            it3 = upper_bound(g.begin(),g.end(),j);
            // cout<<g.end()-it3<<endl;
            ans += g.end()-it3;
            //   it3 = lower_bound(g.begin(),g.end(),k);
            if(binary_search(g.begin(),g.end(),k))
            {
                ans--;
            }
            // cout<<ans<<endl;
            // int temp = g.end()-it3;
            
        }
    }
    cout<<ans<<endl;
}



int main()
{
    fast;
    int t;
    // cin>>t;
    t = 1;
    solve();
    return 0;
}

Measured memory_bytes: 3688