/*
Author- Aasav Badera
Time- Sun Apr 12 17:52:42 2020
*/
#include<bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
// -------------------Standard Traversal Moves---------------------
// vi fx = {1 ,-1 ,0, 0}, fy = {0, 0, -1, 1};
// vi fx = {2, -2, 2, -2,  1, -1, 1, -1}, fy = {1, 1, -1, -1, 2, 2, -2, -2};
// vi fx = {1, 1, 1, -1, -1 , -1, 0, 0}, fy = {1, -1, 0, 1, -1, 0, 1, -1};
// ----------------------------------------------------------------

#define ll                 long long    
#define pb                 push_back                                                     
#define mii                map<ll ,ll >
#define rep(i, a, b)       for(ll  i=a;i<b;i++)
#define pii                pair<ll ,ll >
#define ppb                pop_back
#define vi                 vector<ll >
#define vii                vector<pair<ll , ll >>
#define si                 set <ll>
#define hell               1000000007
// #define hell               (ll)998244353
#define all(a)             (a).begin(),(a).end()
#define sz(x)              (ll )x.size()
#define mp                 make_pair
#define yes                cout << "YES" << endl
#define no                 cout << "NO" << endl
#define inf                1e18L+1
#define endl               '\n' 
#define N                  200005
ll n;


int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // #ifndef ONLINE_JUDGE
    // // for getting input from input.txt
    // freopen("input.txt", "r", stdin);
    // // for writing output to output.txt
    // freopen("output.txt", "w", stdout);
    // #endif
    ll tests = 1;
    // cin >> tests;
    while(tests--)
    {
        cin >> n;
        string s;
        cin >> s;
        vi v[3];
        rep( i,0 ,n)
        {
        	if(s[i] == 'R')v[0].pb(i);
        	else if(s[i] == 'G')v[1].pb(i);
        	else v[2].pb(i);
        }
        ll ptr2 ,ptr3 ,ans = 0;
        rep( i,0 ,3)
        {
        	rep(j ,0, sz(v[i]))
        	{
        		if(lower_bound(all(v[(i+1)%3]), v[i][j]) != v[(i+1)%3].end())
        		{
        			ptr2 = lower_bound(all(v[(i+1)%3]), v[i][j]) - v[(i+1)%3].begin();
        			while(ptr2 < sz(v[(i+1)%3])){
	        			if(lower_bound(all(v[(i+2)%3]),v[(i+1)%3][ptr2]) != v[(i+2)%3].end())
	        			{
	        				ptr3 = lower_bound(all(v[(i+2)%3]), v[(i+1)%3][ptr2]) - v[(i+2)%3].begin();
	        				while(ptr3 < sz(v[(i+2)%3]))
	        				{
	        					if(v[(i+2)%3][ptr3] - v[(i+1)%3][ptr2] != v[(i+1)%3][ptr2] - v[i][j])
	        					{
	        						ans++;
	        					}
	        					ptr3++;
	        				}
	        			}
	        			ptr2++;
        			}
        		}

        		if(lower_bound(all(v[(i+2)%3]), v[i][j]) != v[(i+2)%3].end())
        		{
        			ptr2 = lower_bound(all(v[(i+2)%3]), v[i][j]) - v[(i+2)%3].begin();
        			while(ptr2 < sz(v[(i+2)%3])){
	        			if(lower_bound(all(v[(i+1)%3]),v[(i+2)%3][ptr2]) != v[(i+1)%3].end())
	        			{
	        				ptr3 = lower_bound(all(v[(i+1)%3]), v[(i+2)%3][ptr2]) - v[(i+1)%3].begin();
	        				while(ptr3 < sz(v[(i+1)%3]))
	        				{
	        					if(v[(i+1)%3][ptr3] - v[(i+2)%3][ptr2] != v[(i+2)%3][ptr2] - v[i][j])
	        					{
	        						ans++;
	        					}
	        					ptr3++;
	        				}
	        			}
	        			ptr2++;
        			}
        		}
        	}
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3704