#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>

#include <numeric>

#include <map>

#include <deque>

#include <cassert>

#include <memory>

#include <numeric>

using namespace std;

typedef unsigned long long LL;

char s[4444];

int r[4444], g[4444], b[4444], n;

LL ans;

LL get_ans(char x, char y, int i, int j) {
    LL ret = 0;
    char z;
    map<char, int> m;
    m['R'] = 1;
    m['B'] = 1;
    m['G'] = 1;
    m[x] -= 1;
    m[y] -= 1;
    if (m['R'] == 1) z = 'R';
    if (m['G'] == 1) z = 'G';
    if (m['B'] == 1) z = 'B';
    if (z == 'R') {
        ret = r[n] - r[j];
    }
    if (z == 'G') {
        ret = g[n] - g[j];
    }
    if (z == 'B') {
        ret = b[n] - b[j];
    }
    if (j + j - i <= n) {
        char zz = s[j + j - i];
        //cout << zz << endl;
        if (zz != x && zz != y) ret -= 1;
    }

    //cout << x << ' ' << y << ' ' << i << ' ' << j << ' ' << ret << endl;

    return ret;

}

int main() {

    cin >> n;

    scanf("%s", s + 1);

    for (int i = 1; i <= n; ++i) {
        r[i] = r[i - 1];
        g[i] = g[i - 1];
        b[i] = b[i - 1];
        if (s[i] == 'R') r[i] += 1;
        if (s[i] == 'G') g[i] += 1;
        if (s[i] == 'B') b[i] += 1;
    }

    for (int i = 1; i <= n; ++i) {
        for (int j = i + 1; j <= n; ++j) {
            if (s[j] == s[i]) continue;
            ans += get_ans(s[i], s[j], i, j);
        }
    }

    cout << ans << endl;


}