#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

int main(){
    int n;
    cin >> n;
    
    string s;
    cin >> s;

	map<char,ll> cnts;
	for (char c : s) cnts[c]++;
    
    ll ret = cnts['R'] * cnts['G'] * cnts['B'];
    for (int i = 0; i < n; i++){
        for (int j = i; j < n; j += 2){
            if (s[i] != s[j] &&
				s[i] != s[(i + j) / 2] && 
				s[j] != s[(i + j) / 2]
			) {
				ret--;
			}
        }
    }
    
    cout << ret << endl;
}
