#include <bits/stdc++.h>
#define ll long long
using namespace std;
const long long mod = 1e9+7;
long long power(long long a, long long b, long long m = mod) {
    if(b < 0) {
        return power(power(a, -b), mod-2);
    }
    long long x = 1;
    while(b) {
        if(b & 1) {
            x = 1ll * x * a % m;
        }
        a = 1ll * a * a % m;
        b /= 2;
    }
    return x;
}
const int N = 4000+9;
ll f[N][N][3];
ll fs[N][3];
int a[N];
signed main() {  
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
    int n; cin >> n;
    string s; cin >> s;
    for(int i = 0; i < n; i++) {
        if(s[i] == 'R') a[i] = 1;
        else if(s[i] == 'G') a[i] = 2;
    }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < i; j++) {
            if(a[i] != a[j]) {
                f[i][i-j][a[i]^a[j]^3]++;
                fs[i][a[i]^a[j]^3]++;
            }
        }
    }
    ll ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < i; j++) {
            if(a[i] != a[j]) {
                ans += fs[j][a[i]] - f[j][i-j][a[i]];
            }
        }    
    }
    cout << ans << "\n";






    return 0;
    
}