#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>

using namespace std;

int main()
{
    int  n;
    string s;
    long long a[3] = {0};
    
    cin >> n;
    cin >> s;
    
    for (int i = 0;i < n;i++){
        if (s[i] == 'R'){
            a[0]++;
        }
        else if (s[i] == 'G'){
            a[1]++;
        }
        else {
            a[2]++;
        }
    }
    
    long long sum = 0;
    for (int i = 0;i <= n-3;i++){
        for (int j = 1;i+2*j < n;j++){
            if (s[i] != s[i+j] && s[i+j] != s[i+2*j] && s[i+2*j] != s[i]){
                sum++;
            }
        }
    }
    
    cout << a[0]*a[1]*a[2]-sum << endl;
    
    
    
}
