import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdlib;

void main() {
    auto N = readln.chomp.to!int;
    auto S = readln.chomp;

    auto R = new int[](N+1);
    auto G = new int[](N+1);
    auto B = new int[](N+1);

    foreach (i; 0..N) R[i+1] += R[i] + (S[i]=='R');
    foreach (i; 0..N) G[i+1] += G[i] + (S[i]=='G');
    foreach (i; 0..N) B[i+1] += B[i] + (S[i]=='B');

    long ans = 0;

    foreach (i; 0..N) foreach (k; i+2..N) if (S[i] != S[k]) {
        int par = (k - i + 1) % 2;
        int mid = (k + i) / 2;
        if ((S[i] == 'R' && S[k] == 'G') || (S[i] == 'G' && S[k] == 'R')) {
            ans += B[k+1] - B[i];
            if (par) ans -= S[mid] == 'B';
        } else if ((S[i] == 'R' && S[k] == 'B') || (S[i] == 'B' && S[k] == 'R')) {
            ans += G[k+1] - G[i];
            if (par) ans -= S[mid] == 'G';
        } else if ((S[i] == 'B' && S[k] == 'G') || (S[i] == 'G' && S[k] == 'B')) {
            ans += R[k+1] - R[i];
            if (par) ans -= S[mid] == 'R';
        }
    }

    ans.writeln;
}