#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }

int main(){
    int n; cin >> n;
    string s; cin >> s;
    ll ans = 0;
    rep(i,n-3){
        if(s[i] == 'R'){
            for(int j = i+1; j < n-1; j++){
                if(s[j] == 'R') continue;
                if(s[j] == 'G'){
                    for(int k = j+1; k < n; k++){
                        if(k-j == j-i) continue;
                        if(s[k] == 'B') ans++;
                    }
                }
                if(s[j] == 'B'){
                    for(int k = j+1; k < n; k++){
                        if(k-j == j-i) continue;
                        if(s[k] == 'G') ans++;
                    }
                }
            }
        } else if(s[i] == 'G'){
            for(int j = i+1; j < n-1; j++){
                if(s[j] == 'G') continue;
                if(s[j] == 'R'){
                    for(int k = j+1; k < n; k++){
                        if(k-j == j-i) continue;
                        if(s[k] == 'B') ans++;
                    }
                }
                if(s[j] == 'B'){
                    for(int k = j+1; k < n; k++){
                        if(k-j == j-i) continue;
                        if(s[k] == 'R') ans++;
                    }
                }
            }
        } else if(s[i] == 'B'){
            for(int j = i+1; j < n-1; j++){
                if(s[j] == 'B') continue;
                if(s[j] == 'R'){
                    for(int k = j+1; k < n; k++){
                        if(k-j == j-i) continue;
                        if(s[k] == 'G') ans++;
                    }
                }
                if(s[j] == 'G'){
                    for(int k = j+1; k < n; k++){
                        if(k-j == j-i) continue;
                        if(s[k] == 'R') ans++;
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}
