#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define debug(x) cout << #x << " = " << x << '\n'
#define debug_arr(a , n) for(int i = 0 ; i < n ; i++)cout << a[i] << " "
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define vll vector<ll> 
#define inf 1000000000
#define mod 1000000007

const int max_n = 1e5 + 9;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a , ll b)
{
    ll prod = 1;
    while(b)
    {
        if(b&1)
        prod = (prod*a)%mod;
        a = (a*a)%mod;
        b >>= 1;
    }
    return prod;
}
int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;

    vector<int> r , g , b;
    for(int i = 0 ; i < n ; i++)
    {
        if(s[i] == 'R')r.pb(i);
        if(s[i] == 'G')g.pb(i);
        if(s[i] == 'B')b.pb(i);
    }
    ll sum = 0;
    int red = r.size() , blue = b.size() , green = g.size();
    // red blue
    for(int i = 0 ; i < n ; i++)
    {
        for(int j = i+1 ; j < n ; j++)
        {
            if(s[i] != 'R' || s[j] != 'B')continue;
            int num = (2*j - i);
            int index = upper_bound(g.begin() , g.end() , j) - g.begin();
            int ans = green - index;

            auto it = find(g.begin() , g.end() , num);
            if(it != g.end())
            {
                ans--;
            }

            sum += ans;
        }
    }
    for(int i = 0 ; i < n ; i++)
    {
        for(int j = i+1 ; j < n ; j++)
        {
            if(s[i] != 'B' || s[j] != 'R')continue;
            int num = (2*j - i);
            int index = upper_bound(g.begin() , g.end() , j) - g.begin();
            int ans = green - index;

            auto it = find(g.begin() , g.end() , num);
            if(it != g.end())
            {
                ans--;
            }

            sum += ans;
        }
    }

    for(int i = 0 ; i < n ; i++)
    {
        for(int j = i+1 ; j < n ; j++)
        {
            if(s[i] != 'R' || s[j] != 'G')continue;
            int num = (2*j - i);
            int index = upper_bound(b.begin() , b.end() , j) - b.begin();
            int ans = blue - index;

            auto it = find(b.begin() , b.end() , num);
            if(it != b.end())
            {
                ans--;
            }

            sum += ans;
        }
    }

    for(int i = 0 ; i < n ; i++)
    {
        for(int j = i+1 ; j < n ; j++)
        {
            if(s[i] != 'G' || s[j] != 'R')continue;
            int num = (2*j - i);
            int index = upper_bound(b.begin() , b.end() , j) - b.begin();
            int ans = blue - index;

            auto it = find(b.begin() , b.end() , num);
            if(it != b.end())
            {
                ans--;
            }

            sum += ans;
        }
    }

    for(int i = 0 ; i < n ; i++)
    {
        for(int j = i+1 ; j < n ; j++)
        {
            if(s[i] != 'B' || s[j] != 'G')continue;
            int num = (2*j - i);
            int index = upper_bound(r.begin() , r.end() , j) - r.begin();
            int ans = red - index;

            auto it = find(r.begin() , r.end() , num);
            if(it != r.end())
            {
                ans--;
            }

            sum += ans;
        }
    }

     for(int i = 0 ; i < n ; i++)
    {
        for(int j = i+1 ; j < n ; j++)
        {
            if(s[i] != 'G' || s[j] != 'B')continue;
            int num = (2*j - i);
            int index = upper_bound(r.begin() , r.end() , j) - r.begin();
            int ans = red - index;

            auto it = find(r.begin() , r.end() , num);
            if(it != r.end())
            {
                ans--;
            }

            sum += ans;
        }
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3644