#include<iostream>
#include <algorithm>
#include<iomanip>
#include<math.h>
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
using namespace std;

int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }

int main() {
    int N, R = 0, G = 0, B = 0;
    long long wa = 0;
    char szBuf[5000];
    cin >> N;
    cin >> szBuf;
    for (int x = 0; x < N; x++) {
        if (szBuf[x] == 'R')R++; 
        if (szBuf[x] == 'G')G++;
        if (szBuf[x] == 'B')B++;
    }
    wa = R * G * B;
    for (int x = 0; x < N-2; x++) {
        for (int y = x + 1; y < N-1; y++) {
            if (2 * y - x == N)break;
            if (szBuf[x] == 'R' && szBuf[y] == 'G'&&szBuf[2 * y - x] == 'B')wa--;
            if (szBuf[x] == 'R' && szBuf[y] == 'B'&&szBuf[2 * y - x] == 'G')wa--;
            if (szBuf[x] == 'G' && szBuf[y] == 'B'&&szBuf[2 * y - x] == 'R')wa--;
            if (szBuf[x] == 'G' && szBuf[y] == 'R'&&szBuf[2 * y - x] == 'B')wa--;
            if (szBuf[x] == 'B' && szBuf[y] == 'R'&&szBuf[2 * y - x] == 'G')wa--;
            if (szBuf[x] == 'B' && szBuf[y] == 'G'&&szBuf[2 * y - x] == 'R')wa--;
        }
    }if (wa < 0)wa = 0;
    cout<<wa<<endl;
    return 0;
}