#include<bits/stdc++.h>
using namespace std; 
using lint  =                           long long int;
using pint  =                           pair<int, int>;
using plint =                           pair<lint, lint>;
#define vli                             vector<lint>
#define pb                              push_back
#define ALL(x)                          begin(x),end(x)
#define inf                             (1LL<63)-1
#define MOD                             1000000007
#define SZ(x)                           ((lint)(x).size())
#define                                 FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define                                 IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define                                 REP(i, n) FOR(i,0,n)
#define                                 IREP(i, n) IFOR(i,0,n)
#define                                 f_ip   ios_base::sync_with_stdio(false); cin.tie(NULL);
#define                                 debug(x) cerr << #x << " " << (x) << endl
struct fast_ios                         { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T>                    istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T>                    bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T>                    bool mmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }


/* -------
         |
    **   |
   -------      
   |
   ---------------------------------------------------------------------------------------------------------------------------------*/

void solve(){  
    int N;
    cin >> N;
    string S;
    cin >> S;

    
    vector<int> countB(N,0);
    vector<int> countG(N,0);
    vector<int> countR(N,0);
    if(S[N-1] == 'B') countB[N-1] = 1;
    if(S[N-1] == 'G') countG[N-1] = 1;
    if(S[N-1] == 'R') countR[N-1] = 1;

    for(int i = N-2;i >= 0; --i) { 
          if(S[i] == 'B') { 
              countB[i] += 1;
          }
          countB[i] += countB[i+1];

    }
    for(int i = N-2;i >= 0; --i) { 
          if(S[i] == 'G') { 
              countG[i] += 1;
          }
          countG[i] += countG[i+1];

    }
    for(int i = N-2;i >= 0; --i) { 
          if(S[i] == 'R') { 
              countR[i] += 1;
          }
          countR[i] += countR[i+1];

    }

    lint ret = 0;
    for(int i = 0;i <= N-3; ++i) { 
        for(int j = i+1;j <= N-2; ++j) { 
                if(S[i] == 'R' && S[j] == 'G') { 
                          int diff = j - i;
                          ret += countB[j+1];

                          if(j + diff <= N-1) {
                              if(S[j+diff] == 'B') --ret;   //only exceptional case;
                          }
                }
               
               if(S[i] == 'R' && S[j] == 'B') { 
                          int diff = j - i;
                          ret += countG[j+1];

                          if(j + diff <= N-1) {
                              if(S[j+diff] == 'G') --ret;   //only exceptional case;
                          }
                }
                
                 if(S[i] == 'G' && S[j] == 'R') { 
                          int diff = j - i;
                          ret += countB[j+1];

                          if(j + diff <= N-1) {
                              if(S[j+diff] == 'B') --ret;   //only exceptional case;
                          }
                }
                 if(S[i] == 'G' && S[j] == 'B') { 
                          int diff = j - i;
                          ret += countR[j+1];

                          if(j + diff <= N-1) {
                              if(S[j+diff] == 'R') --ret;   //only exceptional case;
                          }
                }
                 if(S[i] == 'B' && S[j] == 'R') { 
                          int diff = j - i;
                          ret += countG[j+1];

                          if(j + diff <= N-1) {
                              if(S[j+diff] == 'G') --ret;   //only exceptional case;
                          }
                }
                 if(S[i] == 'B' && S[j] == 'G') { 
                          int diff = j - i;
                          ret += countR[j+1];

                          if(j + diff <= N-1) {
                              if(S[j+diff] == 'R') --ret;   //only exceptional case;
                          }
                }
        }
    }

    cout << ret << endl;
}

int main(){   
  
 solve();

 return 0;
}


Measured memory_bytes: 3668