#include<bits/stdc++.h>
#define fr first
#define se second
#define pb push_back
#define ll long long
#define TIME ios_base::sync_with_stdio(0);
using namespace std;
ll cnt, a , b , c , n , m , mx ,d , sum , temp , mx1;
const ll N = 1e4;
string s;
int main(){
    cin >> n >> s;
    for( int i = 0;i < n;i ++ ){
        if( s[i] == 'R' )
            a ++;
        if( s[i] == 'G' )
            b ++;
        if( s[i] == 'B' )
            c ++;
    }
    cnt = a * b * c;
    for( int i = 0;i < n;i ++ ){
        for( int j = 0;j * 2 + i < n;j ++ ){
            if( s[i] == 'R' and s[i + j] == 'G' and s[i + j * 2] == 'B' )
                cnt --;
            else if( s[i] == 'R' and s[i + j] == 'B' and s[i + j * 2] == 'G' )
                cnt --;
            else if(s[i] == 'B' and s[i + j] == 'R' and s[i + j * 2] == 'G' )
                cnt --;
            else if( s[i] == 'B' and s[i + j] == 'G' and s[i + j * 2] == 'R' )
                cnt --;
            else if( s[i] == 'G' and s[i + j] == 'B' and s[i + j * 2] == 'R' )
                cnt --;
            else if( s[i] == 'G' and s[i + j] == 'R' and s[i + j * 2] == 'B' )
                cnt --;
        }
    }
    cout << cnt;
}
