#include<iostream>
#include<map>

using namespace std;

int main() {
    int n;
    string s;
    cin >> n >> s;

    map<char, int> rgb_num;
    rgb_num['R'] = 0;
    rgb_num['G'] = 0;
    rgb_num['B'] = 0;
    for(int i = 0; i < n; i++) {
        rgb_num[s[i]]++;
    }

    int64_t ans = 0;
    int r_num = rgb_num['R'], g_num = rgb_num['G'], b_num = rgb_num['B'];
    map<char, int> through_rgb_num;
    through_rgb_num['R'] = 0;
    through_rgb_num['G'] = 0;
    through_rgb_num['B'] = 0;
    int through_r_num, through_g_num, through_b_num;
    for(int i = 0; i < n - 2; i++) {
        char si = s[i];
        rgb_num[si]--;
        through_r_num = r_num - rgb_num['R'];
        through_g_num = g_num - rgb_num['G'];
        through_b_num = b_num - rgb_num['B'];
        for(int j = i + 1; j < n - 1; j++) {
            char sj = s[j];
            if(sj == 'R')      through_r_num++;
            else if(sj == 'G') through_g_num++;
            else               through_b_num++;
            
            if(sj == si) continue;
            
            char sk;
            if((si == 'R' && sj == 'G') || (si == 'G' && sj == 'R'))       sk = 'B';
            else if ((si == 'G' && sj == 'B') || (si == 'B' && sj == 'G')) sk = 'R';
            else                                                           sk = 'G';

            if(sk == 'R')      ans += r_num - through_r_num;
            else if(sk == 'G') ans += g_num - through_g_num;
            else               ans += b_num - through_b_num;

            //cout << "sk: " << sk << ", ans: " << ans << endl;

            if(2 * j - i < n) {
                if(s[2 * j - i] == sk) ans--;
            }
        }
    }

    cout << ans << endl;

    return 0;
}