#include <bits/stdc++.h>
#include <set>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef char chr;
typedef double  dbl;
typedef long long int lld;
#define FastIO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
lld lowerIndex(lld arr[], lld n, lld x) 
{ 
    lld l = 0 , h = n - 1;
    while (l <= h) { 
        lld mid = (l+h)/2;
        if (arr[mid] >= x) 
            h = mid - 1; 
        else
            l = mid + 1; 
    } 
    return l; 
}
lld upperIndex(lld arr[], lld n, lld y)
{ 
    lld l = 0 , h = n - 1; 
    while (l <= h) { 
        lld mid = (l+h)/2; 
        if (arr[mid] <= y) 
            l = mid + 1; 
        else
            h = mid - 1; 
    } 
    return h; 
}
lld countInRange(lld arr[], lld n, lld x, lld y) 
{
    lld count = 0; 
    count = upperIndex(arr, n, y) - lowerIndex(arr, n, x) + 1; 
    return count; 
}
int main () {
    FastIO
    lld n, i;
    cin >> n;
    string s;
    cin >> s;
    lld j, k;
    lld R[n];
    lld G[n];
    lld B[n];
    lld a, b;
    lld c;
    a = 0;
    b = 0;
    c = 0;
    for(i = 0; i < n-0; i+=1){
    	if (s[i] == 'R'){
    		R[a] = i;
    		a++;
    	}
    	if (s[i] == 'G'){
    		G[b] = i;
    		b++;
    	}
    	if (s[i] == 'B'){
    		B[c] = i;
    		c++;
    	}
    }
    lld sum = 0;
    for(i = 0; i < n-2; i+=1){
    	for(k = i+2;k<n;k+=1){
    		if (s[i] != s[k]){
    			if (s[i] == 'R' && s[k] == 'G'){
    				sum+= countInRange(B,c,i,k);
    				if ((i+k) % 2 == 0 && s[(i+k)/2] == 'B'){
    					sum--;
    				}
    			}
    			if (s[i] == 'R' && s[k] == 'B'){
    				sum+= countInRange(G,b,i,k);
    				if ((i+k) % 2 == 0 && s[(i+k)/2] == 'G'){
    					sum--;
    				}
    			}
    			if (s[i] == 'G' && s[k] == 'R'){
    				sum+= countInRange(B,c,i,k);
    				if ((i+k) % 2 == 0 && s[(i+k)/2] == 'B'){
    					sum--;
    				}
    			}
    			if (s[i] == 'G' && s[k] == 'B'){
    				sum+= countInRange(R,a,i,k);
    				if ((i+k) % 2 == 0 && s[(i+k)/2] == 'R'){
    					sum--;
    				}
    			}
    			if (s[i] == 'B' && s[k] == 'G'){
    				sum+= countInRange(R,a,i,k);
    				if ((i+k) % 2 == 0 && s[(i+k)/2] == 'R'){
    					sum--;
    				}
    			}
    			if (s[i] == 'B' && s[k] == 'R'){
    				sum+= countInRange(G,b,i,k);
    				if ((i+k) % 2 == 0 && s[(i+k)/2] == 'G'){
    					sum--;
    				}
    			}
    		}
    	}
    }
    cout << sum << "\n";
    return 0;
}