#include<bits/stdc++.h>
using namespace std;

#define ll long long int 
ll mod=1e9+7;

// vector<int> g[200005];
// int vis[200005];
// queue<int> q;
// int level[200005];

// void dfs(int i)
// {
//     vis[i] = 1;
//     for(int j=0;j<g[i].size();j++)
//     {
//         int child = g[i][j];
//         if(vis[child] == 0)
//         {
//             dfs(child);
//         }
//     }
// }

// void bfs(int i)
// {
//     vis[i] = 1;
//     while(!q.empty())
//     {
//         int top = q.front();
//         int len_adj = g[top].size();
//         int j;
//         for(j=0;j<len_adj;j++)
//         {
//             int v = g[top][j];
//             if(vis[v]==0)
//             {
//                 vis[v]=1;
//                 q.push(v);
//                 level[v] = level[top] + 1;
//             }
//         }   
//         q.pop();
//     }
// }

ll modular_exponentiation(ll base, ll power)
{
    ll ans = 1;
    base = base % mod;
    while (power > 0)
    {
        if (power & 1)
        {
            ans = (ans * base) % mod;
        }

        power /= 2;
        base = (base * base) % mod;
    }
    return ans;
}

int main()
{
    /* Faster input ouput */
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.tie(NULL);

    /* To read input from a file and output to a file */
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    
    int t = 1;
    // cin >> t;
    while(t--)
    {        
        ll n,i,j,k;
        cin >> n;
        string s;
        cin >> s;
        vector<ll> R,G,B;
        

        for(i=0;i<n;i++)
        {
            if(s[i] == 'R')
            {
                R.push_back(i+1);
            }
            if(s[i] == 'G')
            {
                G.push_back(i+1);
            }
            if(s[i] == 'B')
            {
                B.push_back(i+1);
            }
        }

        ll R_size = R.size();
        ll G_size = G.size();
        ll B_size = B.size();

        ll ans = 0;

        // R G B
        for(i=0;i<R_size;i++)
        {
            for(k=0;k<B.size();k++)
            {
                if(R[i] < B[k])
                {
                    j = (R[i]+B[k])/2;

                    ll how_many = 0;
                    ll lower_ind = upper_bound(G.begin(),G.end(),R[i]) - G.begin();
                    ll upper_ind = lower_bound(G.begin(),G.end(),B[k]) - G.begin();

                    how_many = upper_ind - lower_ind;
                    if(binary_search(G.begin(),G.end(),j))
                    {
                        if((R[i] + B[k]) % 2 == 0)
                        {
                            if(how_many > 0)
                            {
                                how_many -= 1;
                            }   
                        }
                    }
                    // cout << R[i] << " " << B[k] << " " << j << " " <<  how_many << '\n';
                    ans += how_many;
                }
            }
        }
        //  R B G
        for(i=0;i<R_size;i++)
        {
            for(k=0;k<G.size();k++)
            {
                if(R[i] < G[k])
                {
                    j = (R[i]+G[k])/2;

                    ll how_many = 0;
                    ll lower_ind = upper_bound(B.begin(),B.end(),R[i]) - B.begin();
                    ll upper_ind = lower_bound(B.begin(),B.end(),G[k]) - B.begin();

                    how_many = upper_ind - lower_ind;
                    if(binary_search(B.begin(),B.end(),j))
                    {
                        if((R[i] + G[k]) % 2 == 0)
                        {
                            if(how_many > 0)
                            {
                                how_many -= 1;
                            }   
                        }   
                    }
                    // cout << R[i] << " " << G[k] << " " << j << " " <<  how_many << '\n';
                    ans += how_many;
                }
            }
        }

        // cout << "ans after 1= " << ans << '\n';

        // G R B
        for(i=0;i<G_size;i++)
        {
            for(k=0;k<B.size();k++)
            {
                if(G[i] < B[k])
                {
                    j = (G[i]+B[k])/2;

                    ll how_many = 0;
                    ll lower_ind = upper_bound(R.begin(),R.end(),G[i]) - R.begin();
                    ll upper_ind = lower_bound(R.begin(),R.end(),B[k]) - R.begin();

                    how_many = upper_ind - lower_ind;
                    if(binary_search(R.begin(),R.end(),j))
                    {
                        if((G[i] + B[k]) % 2 == 0)
                        {
                            if(how_many > 0)
                            {
                                how_many -= 1;
                            }   
                        }   
                    }
                    // cout << G[i] << " " << B[k] << " " << j << " " <<  how_many << '\n';
                    ans += how_many;
                }
            }
        }
        // G B R
        for(i=0;i<G_size;i++)
        {
            for(k=0;k<R.size();k++)
            {
                if(G[i] < R[k])
                {
                    j = (G[i]+R[k])/2;

                    ll how_many = 0;
                    ll lower_ind = upper_bound(B.begin(),B.end(),G[i]) - B.begin();
                    ll upper_ind = lower_bound(B.begin(),B.end(),R[k]) - B.begin();

                    how_many = upper_ind - lower_ind;
                    if(binary_search(B.begin(),B.end(),j))
                    {
                        if((G[i] + R[k]) % 2 == 0)
                        {
                            if(how_many > 0)
                            {
                                how_many -= 1;
                            }   
                        }
                    }
                    // cout << G[i] << " " << R[k] << " " << j << " " <<  how_many << '\n';
                    ans += how_many;
                }
            }
        }

        // cout << "ans after 2= " << ans << '\n';

        // B R G
        for(i=0;i<B_size;i++)
        {
            for(k=0;k<G.size();k++)
            {
                if(B[i] < G[k])
                {
                    j = (B[i]+G[k])/2;

                    ll how_many = 0;
                    ll lower_ind = upper_bound(R.begin(),R.end(),B[i]) - R.begin();
                    ll upper_ind = lower_bound(R.begin(),R.end(),G[k]) - R.begin();

                    how_many = upper_ind - lower_ind;
                    if(binary_search(R.begin(),R.end(),j))
                    {
                        if((B[i] + G[k]) % 2 == 0)
                        {
                            if(how_many > 0)
                            {
                                how_many -= 1;
                            }   
                        }
                    }
                    // cout << R[i] << " " << G[k] << " " << j << " " <<  how_many << '\n';
                    ans += how_many;
                }
            }
        }
        // B G R
        for(i=0;i<B_size;i++)
        {
            for(k=0;k<R.size();k++)
            {
                if(B[i] < R[k])
                {
                    j = (B[i]+R[k])/2;

                    ll how_many = 0;
                    ll lower_ind = upper_bound(G.begin(),G.end(),B[i]) - G.begin();
                    ll upper_ind = lower_bound(G.begin(),G.end(),R[k]) - G.begin();

                    how_many = upper_ind - lower_ind;
                    if(binary_search(G.begin(),G.end(),j))
                    {
                        if((B[i] + R[k]) % 2 == 0)
                        {
                            if(how_many > 0)
                            {
                                how_many -= 1;
                            }   
                        }
                    }
                    // cout << R[i] << " " << B[k] << " " << j << " " <<  how_many << '\n';
                    ans += how_many;
                }
            }
        }

        cout << ans << '\n';
    }

    
    
}

Measured memory_bytes: 3668