#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define VLL vector<long long>
#define M map<int, int>
#define S set<int>
#define V vector<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
    int N;  cin >> N;
    string s;  cin >> s;

    int kp[3][4000];
    REP(i, 3)  REP(j, 4000)  kp[i][j] = 0;  //RGB
    if(s[0] == 'R')       kp[0][0]++;
    else if(s[0] == 'G')  kp[1][0]++;
    else if(s[0] == 'B')  kp[2][0]++;
    
    REP(i, N){
      kp[0][i] = kp[0][i - 1];
      kp[1][i] = kp[1][i - 1];
      kp[2][i] = kp[2][i - 1];
      if(s[i] == 'R')       kp[0][i]++;
      else if(s[i] == 'G')  kp[1][i]++;
      else if(s[i] == 'B')  kp[2][i]++;
      
    }


    ll ans = 0;
    for(int i = 1 ;  i < N-1 ; i++){
      if(s[i] == 'R')      ans += kp[1][i-1]*(kp[2][N-1]-kp[2][i]) + kp[2][i-1]*(kp[1][N-1]-kp[1][i]);
      else if(s[i] == 'G') ans += kp[0][i-1]*(kp[2][N-1]-kp[2][i]) + kp[2][i-1]*(kp[0][N-1]-kp[0][i]);
 	  else if(s[i] == 'B') ans += kp[0][i-1]*(kp[1][N-1]-kp[1][i]) + kp[1][i-1]*(kp[0][N-1]-kp[0][i]);
      
      for(int side = 1 ; side <= min(i, N-i-1) ; side++){
        if(s[i] != s[i-side] && s[i] != s[i+side] && s[i+side] != s[i-side])  ans--;
      }
    }

    cout << ans << endl;
  	return 0;
}
