/**
 *      ///----- My Info -----///
 *      Clock: nowl
 *      Code by: Ernesto Abreu
 *      Codeforces User: Ernest0_0Abreu
 *      Country: Cuba
 *      E-mail: ernestoabreup@gmail.com
 *      ©CopyRight
**/
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
        ///----- My Template -----///
///=====================================================================================================================
/// Red-Black Tree
// #include <ext/pb_ds/assoc_container.hpp>  // .find_of_order(x); .order_of_key(x);
// using namespace __gnu_pbds;
// typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > indexed_set;
/// Typedef
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
/// Function
#define pi (acos(-1))
#define lg2(x) 31-__builtin_clz(x)
#define lgx(x,b) log(b)/log(x)
/// Macros
#define fst first
#define scd second
#define pb push_back
#define left (node<<1)
#define right ((node<<1)+1)
#define sz(x) (int)(x.size())
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
/// Debug
#define _end cout << "\n"
#define debug(x) cerr << #x << " = " << x << " "
/// Constant
const int MAXN = 4e3+7;
const int MOD = 1e9+7;
const ull BASE = 311;
const ld EPS = 1e-9;
const int INF = ((1<<30)-1);
const ll INFLL = ((1ll<<62ll)-1ll);
/// Hash Prime Numbers: 2, 277, 293, 307, 331, 337, 1009, 2027;
/// Module Prime Numbers: 3, 998244353, 1000000007, 1000000009, 1000000021, 1000000033;
///=====================================================================================================================
#define int long long
        ///----- My code -----///

int ar[MAXN], iz[MAXN], de[MAXN], Tde;

int32_t main (){

    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    cout.setf(ios::fixed);cout.precision(0);
//  freopen("a.in", "r", stdin);

    int N;
    cin >> N;
    string s;
    cin >> s;
    for(int i = 0; i < sz(s); i++){
        if(s[i] == 'R') ar[i+1] = 0;
        if(s[i] == 'G') ar[i+1] = 1;
        if(s[i] == 'B') ar[i+1] = 2;
    }

    int ans = 0;
    for(int i = 1; i <= N; i++){
        for(int j = i-1; j >= 1; j--){
            if(ar[j] == (ar[i]+1)%3){
                iz[i-j]++;
            }
        }
        for(int j = i+1; j <= N; j++){
            if(ar[j] == (ar[i]+2)%3 ){
                de[j-i]++;
                Tde++;
            }
        }
        for(int k = 1; k <= N; k++){
            ans+=iz[k]*(Tde-de[k]);
        }

        for(int j = 1; j <= N; j++){
            iz[j] = de[j] = 0;
        }
        Tde = 0;
        for(int j = i-1; j >= 1; j--){
            if(ar[j] == (ar[i]+2)%3){
                iz[i-j]++;
            }
        }
        for(int j = i+1; j <= N; j++){
            if(ar[j] == (ar[i]+1)%3 ){
                de[j-i]++;
                Tde++;
            }
        }
        for(int k = 1; k <= N; k++){
            ans+=iz[k]*(Tde-de[k]);
        }
        for(int j = 1; j <= N; j++){
            iz[j] = de[j] = 0;
        }
        Tde = 0;
    }

    cout << ans;

    return 0;
}
/*
Test case:

*/



Measured memory_bytes: 3736