#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
#include <deque>
using ll = long long;
using Graph = vector<vector<int>>;
#include <queue>
#include <stack>


int main(){

    string s;
    int n;
    cin >> n >> s;
    int cnt = 0;
    int r,g,b;
    r = g = b = 0;
    for(int i=0;i < n;i++){
        if(s[i] == 'R') r++;
        if(s[i] == 'G') g++;
        if(s[i] == 'B') b++;
    }

    cnt = r * g * b;

    //補集合の要素数を全体集合の要素数から引く（r * g * b）

    //jとjから等距離にある文字がすべて異なる
    for(int j = 1;j < n;j++){
        for(int diff = 1;diff < n;diff++){
            if(j-diff >= 0 && j + diff < n && s[j - diff] != s[j] && s[j] != s[j + diff] && s[j + diff] != s[j - diff]) cnt--;

        }
    }

    cout << cnt << endl;

    
    return 0;
}