#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
const int N = 200001;
using namespace std;




int main() {
//    cout << fixed << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    int n;
    string s;
    cin >> n >> s;
    int dp[n + 1][3];
    memset(dp, 0, sizeof dp);

    for (int i = 0; i < n; i++) {
        dp[i + 1][0] = dp[i][0];
        dp[i + 1][1] = dp[i][1];
        dp[i + 1][2] = dp[i][2];

        if (s[i] == 'R') ++dp[i + 1][0];
        if (s[i] == 'G') ++dp[i + 1][1];
        if (s[i] == 'B') ++dp[i + 1][2];

    }

    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 3; j < n; j++) {
            if (s[i] != s[j]) {
                int tarL;
                char ot;
                if (s[i] != 'R' && s[j] != 'R') {
                    tarL = 0;
                    ot = 'R';
                }
                if (s[i] != 'G' && s[j] != 'G') {
                    tarL = 1;
                    ot = 'G';
                }
                if (s[i] != 'B' && s[j] != 'B') {
                    tarL = 2;
                    ot = 'B';
                }

                ans += dp[j][tarL] - dp[i + 1][tarL];
                if ((j - i) % 2 == 0 && s[(i + j) / 2] == ot) {
                    --ans;
                }
            }
        }
    }

    cout << ans;


}
