//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//

inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve()
{
    int n;
    seika s;
    cin >> n >> s;
    i64 ans = 0;
    for (int j = 1; j < n - 1; j++)
    {
        akari<int> lc(3), rc(3);
        for (int i = 0; i < j; i++)
        {
            if (s[i] == s[j])
            {
                continue;
            }
            if (s[i] == 'R')
            {
                lc[0]++;
            }
            if (s[i] == 'G')
            {
                lc[1]++;
            }
            if (s[i] == 'B')
            {
                lc[2]++;
            }
        }
        for (int k = j + 1; k < n; k++)
        {
            if (s[k] == s[j])
            {
                continue;
            }
            if (s[k] == 'R')
            {
                rc[0]++;
            }
            if (s[k] == 'G')
            {
                rc[1]++;
            }
            if (s[k] == 'B')
            {
                rc[2]++;
            }
        }
        for (int i = 0; i < 3; i++)
            for (int k = 0; k < 3; k++)
            {
                if (i == k)
                {
                    continue;
                }
                ans += i64(1) * lc[i] * rc[k];
            }
        for (int d = 1; j - d >= 0 && j + d < n; d++)
        {
            if (s[j - d] != s[j] && s[j] != s[j + d] && s[j - d] != s[j + d])
            {
                ans--;
            }
        }
    }
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}
