#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>

using namespace std;

map <string,vector<int>> m;
map <int, string> r;

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int num[3] = {0};

    for (int i = 0;i < n;i++){
        r[i] = s[i];
        if (s[i] == 'B'){
            m["B"].push_back(i);
            num[0]++;
        }
        else if (s[i] == 'R'){
            m["R"].push_back(i);
            num[1]++;
        }
        else if (s[i] == 'G'){
            m["G"].push_back(i);
            num[2]++;
        }
    }

    long long sum = 0;
    for (int i = 0;i < n-2;i++){
        for (int j = 1;i+2*j<n;j++){
            if (r[i] != r[i+j] && r[i+j] != r[i+2*j] && r[i+2*j] != r[i]){
                sum++;
            }
        }
    }
    long long seki = num[0]*num[1]*num[2];

    cout << seki-sum << endl;
}
