#include <bits/stdc++.h>
using namespace std;

#define    ll     long long int

const int N = 4005;
pair<int, int> cnt_g[N];
pair<int, int> cnt_b[N];
pair<int, int> cnt_r[N];
int n;
string s;

int main( )
{
    int i, j, k;
    ll ans = 0;
    cin >> n >> s;
    s = " " + s;
    for (i = 1; i <= n; i++) {
        cnt_r[i].first += cnt_r[i - 1].first;
        cnt_g[i].first += cnt_g[i - 1].first;
        cnt_b[i].first += cnt_b[i - 1].first;
        if (s[i] == 'R')        cnt_r[i].first++;
        else if (s[i] == 'G')   cnt_g[i].first++;
        else                    cnt_b[i].first++;
    }
    for (i = n; i >= 1; i--) {
        cnt_r[i].second += cnt_r[i + 1].second;
        cnt_g[i].second += cnt_g[i + 1].second;
        cnt_b[i].second += cnt_b[i + 1].second;
        if (s[i] == 'R')        cnt_r[i].second++;
        else if (s[i] == 'G')   cnt_g[i].second++;
        else                    cnt_b[i].second++;
    }
    for (j = 2; j < n; j++) {
        if (s[j] == 'G') {
            for (i = 1; i < j; i++) {
                if (s[i] == 'B') {
                    k = 2 * j - i;
                    if (k <= n && s[k] == 'R') {
                        ans += max(0, cnt_r[j].second - 1);
                    }
                    else {
                        ans += cnt_r[j].second;
                    }
                }
                if (s[i] == 'R') {
                    k = 2 * j - i;
                    if (k <= n && s[k] == 'B') {
                        ans += max(0, cnt_b[j].second - 1);
                    }
                    else {
                        ans += cnt_b[j].second;
                    }
                }
            }
        }
        else if (s[j] == 'B') {
            for (i = 1; i < j; i++) {
                if (s[i] == 'G') {
                    k = 2 * j - i;
                    if (k <= n && s[k] == 'R') {
                        ans += max(0, cnt_r[j].second - 1);
                    }
                    else {
                        ans += cnt_r[j].second;
                    }
                }
                if (s[i] == 'R') {
                    k = 2 * j - i;
                    if (k <= n && s[k] == 'G') {
                        ans += max(0, cnt_g[j].second - 1);
                    }
                    else {
                        ans += cnt_g[j].second;
                    }
                }
            }
        }
        else if (s[j] == 'R') {
            for (i = 1; i < j; i++) {
                if (s[i] == 'G') {
                    k = 2 * j - i;
                    if (k <= n && s[k] == 'B') {
                        ans += max(0, cnt_b[j].second - 1);
                    }
                    else {
                        ans += cnt_b[j].second;
                    }
                }
                if (s[i] == 'B') {
                    k = 2 * j - i;
                    if (k <= n && s[k] == 'G') {
                        ans += max(0, cnt_g[j].second - 1);
                    }
                    else {
                        ans += cnt_g[j].second;
                    }
                }
            }
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3704