// Nguyen Anh Tu
#include <bits/stdc++.h>
#define FOR(x,a,b) for(int x=a;x<=b;x++)
#define FORD(x,a,b) for(int x=a;x>=b;x--)
#define maxn 4005
#define maxc 1000000007
#define MOD 1000000007
#define reset(x, y) memset(x,y,sizeof(x))
#define task ""
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define pii pair<int,int>
#define ll long long
#define bit(p,x) ((x>>p) & 1)
#define remain(a,b) (a+b >= MOD) ? (a+b - MOD) : (a+b)
using namespace std;
int k, n;
string s;
ll ans;
int d[maxn][maxn];
int main()
{
    ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL);
    if(fopen(task".inp", "r"))
    {
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    cin >> n >> s;
    s = ' ' + s;
    for(int i=1; i<=n; ++i)
    {
        d[i]['R'] = d[i-1]['R']+(s[i] == 'R');
        d[i]['G'] = d[i-1]['G']+(s[i] == 'G');
        d[i]['B'] = d[i-1]['B']+(s[i] == 'B');
    }
    int sum = 'R' + 'G' + 'B';
    for(int i=1; i<=n ;++i)
        for(int j=1; j<i; ++j)
        {
            if(s[i] != s[j])
            {
                int k = sum - s[i] - s[j];
                int x = i - j;
                x = j - x;
                if(s[x] == k) ans --;
                ans += d[j-1][k];
            }
        }
    cout << ans;
    return 0;
}
