#include <iostream>
#include <typeinfo>
#include <cstring>
#include <utility>
#include <vector>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std;


int main() {
    unsigned int N;
    cin >> N;

    string s;
    cin >> s;

    unsigned int numR = 0;
    unsigned int numG = 0;
    unsigned int numB = 0;

    for (int i = 0; i < N; i++) {
        if (s[i] == 'R') numR++;
        else if (s[i] == 'G') numG++;
        else if (s[i] == 'B') numB++;
    }

    unsigned int comp = 0;
    for (unsigned int j = 1; j < N - 1; j++) {
        unsigned int maxD = min(j, N - j - 1);
        for (unsigned int d = 1; d <= maxD; d++) {
            unsigned int i = j - d;
            unsigned int k = j + d;
            if (s[i] != s[j] && s[j] != s[k] && s[k] != s[i]) comp++;
        }
    }

    cout << numR * numG * numB - comp << endl;
    return 0;
}
