#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<algorithm>
// #include<bits/stdc++.h>
#define INF 0x7f7f7f7f //2139062143
#define INF1 0x3f3f3f3f //1061109567
#define INF2 2147483647
#define llINF 9223372036854775807
#define pi 3.141592653589793//23846264338327950254
#define ft first
#define sd second
#define pb push_back
#define ll long long
#define vec vector<ll>
#define mat vector<vector<ll>>
//cout<<fixed<<setprecision(6)<<
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
//ifstream f1("/Users/wangzichao/Documents/wzc.in");
//ofstream f2("/Users/wangzichao/Documents/wzc.out");
//ios::sync_with_stdio(false);
//cin.tie(0);cout.tie(0);
using namespace std;
#define local
#ifdef local
#endif
const ll maxn=6e5+7;
const double eps=1e-10;
// const ll mod=1e9+7;
#define STDIN freopen("in.txt","r",stdin); freopen("out.txt","w",stdout);//************************************
#define Quick ios::sync_with_stdio(false);cin.tie(NULL);


// int gcd(int a, int b)
// {
//     return b?gcd(b, a%b):a;
// }
// int main()
// {
//     Quick;
//     STDIN;
//     int k; cin >> k;
//     ll sum = 0;
//     for (int i = 1; i <= k; i++)
//     {
//         for (int j = 1; j <= k; j++)
//         {
//             for (int l = 1; l <= k; l++)
//             {
//                 sum += gcd(gcd(i, j), l);
//             }
//         }
//     }
//     cout << sum << endl;
// }

ll dp[4];
int main(){
    // STDIN
    Quick
    int n;
    cin >> n;
    string s;
    cin >> s;
    memset(dp,0,sizeof(dp));
    ll sum = 0;
    for (int i = 0; i < n; ++i)
    {
        dp[3] = (dp[3] + (s[i] == 'B')*dp[2])  ;
        dp[2] = (dp[2] + (s[i] == 'G')*dp[1])  ;
        dp[1] = (dp[1] + (s[i] == 'R'))  ;
    }
    sum += dp[3];
    // cout << sum << endl;
    memset(dp,0,sizeof(dp));
    for (int i = 0; i < n; ++i)
    {
        dp[3] = (dp[3] + (s[i] == 'G')*dp[2])  ;
        dp[2] = (dp[2] + (s[i] == 'B')*dp[1])  ;
        dp[1] = (dp[1] + (s[i] == 'R'))  ;
    }
    sum += dp[3];
    memset(dp,0,sizeof(dp));
    for (int i = 0; i < n; ++i)
    {
        dp[3] = (dp[3] + (s[i] == 'R')*dp[2])  ;
        dp[2] = (dp[2] + (s[i] == 'G')*dp[1])  ;
        dp[1] = (dp[1] + (s[i] == 'B'))  ;
    }
    sum += dp[3];

    memset(dp,0,sizeof(dp));
    for (int i = 0; i < n; ++i)
    {
        dp[3] = (dp[3] + (s[i] == 'G')*dp[2])  ;
        dp[2] = (dp[2] + (s[i] == 'R')*dp[1])  ;
        dp[1] = (dp[1] + (s[i] == 'B'))  ;
    }
    sum += dp[3];

    memset(dp,0,sizeof(dp));
    for (int i = 0; i < n; ++i)
    {
        dp[3] = (dp[3] + (s[i] == 'R')*dp[2])  ;
        dp[2] = (dp[2] + (s[i] == 'B')*dp[1])  ;
        dp[1] = (dp[1] + (s[i] == 'G'))  ;
    }
    sum += dp[3];
    memset(dp,0,sizeof(dp));
    for (int i = 0; i < n; ++i)
    {
        dp[3] = (dp[3] + (s[i] == 'B')*dp[2])  ;
        dp[2] = (dp[2] + (s[i] == 'R')*dp[1])  ;
        dp[1] = (dp[1] + (s[i] == 'G'))  ;
    }
    sum += dp[3];
    ll cnt = 0ll;
    for (int i = 0; i < n; i++)
    {
        int j = 1;
        while (i-j >= 0 && i + j < n){
            if (s[i] != s[i+j] && s[i] != s[i-j] && s[i-j] != s[i+j]) cnt++;
            j++;
        }
    }
   // cout << sum << endl;
    cout << sum - cnt << endl;
    return 0;
 
}

Measured memory_bytes: 3196