#include <bits/stdc++.h>
#define int long long
#define all(c) (c).begin(),(c).end()
#define pii pair<long long,long long>
#define endl '\n'

using namespace std;

signed main(){
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector <char> A(n,'a');
    for(int i=0;i<n;i++){
        cin >> A[i];
    }
    int ans=0;
    for(int i=0;i<n-2;i++){
        //if(A[i]=='R'){
            for(int j=i+1;j<n-1;j++){
                //if(A[j]=='G'){
                    for(int k=j+1;k<n;k++){
                        //if(A[k]=='B'){
                            if(k-j==j-i){
                                
                            }
                            else if(A[i]==A[j] || A[i]==A[k] || A[j]==A[k]){
                                
                            }
                            else ans++;
                        //}
                    }
                //}
            }
        //}
    }
    cout << ans;
}