#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;

int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

int main(){
    int n;
    string s;
    cin>>n;
    cin>>s;
    int r = 0;
    int g = 0;
    int b = 0;
    rep(i,0,n-1){
        if(s[i]=='R') r++;
        if(s[i]=='G') g++;
        if(s[i]=='B') b++;
    }
    int ans = r*g*b;
    int j,k;

    rep(i,1,n){
        rep(d,1,n){
            j = i + d;
            k = j + d;
            if(k>n) break;
            if(s[i-1]!=s[j-1]&&s[i-1]!=s[k-1]&&s[j-1]!=s[k-1]) ans--;
        }
    }
    cout<<ans<<endl;
    return 0;
}