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

int main() {
    int n;
    string s;
    cin >> n >> s;
    
    long long r = 0, g = 0, b = 0;
    for (const char &c : s) {
        r += (c == 'R');
        g += (c == 'G');
        b += (c == 'B');
    }
    
    long long ans = r * g * b;
    
    auto f = [&](int i, int j, int k) -> bool {
        return (s[i] != s[j] and s[j] != s[k] and s[k] != s[i]);
    };
    
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            const int d = j - i;
            if (j + d < n) ans -= f(i, j, j + d);
        }
    }
    
    cout << ans << '\n';
    return 0;
}