#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long unsigned int ll;

int main()
{
    int n;
    string s;
    cin >> n >> s;
    long long ans = 0;
    vector<int> red, green, blue;
    red.at(0) = 0;
    green.at(0) = 0;
    blue.at(0) = 0;
    for (int i = 1; i < n; i++)
    {
        if (s.at(i) == 'R')
        {
            red.at(i) = red.at(i - 1) + 1;
        }
        else if (s.at(i) == 'G')
        {
            green.at(i) = green.at(i - 1) + 1;
        }
        else
        {
            blue.at(i) = blue.at(i - 1) + 1;
        }
    }

    rep(i, n)
    {

        if (s.at(i) == 'R')
        {
            ans += blue.at(i) * (green.at(n - 1) - green.at(i)) + green.at(i) * (blue.at(n - 1) - blue.at(i));
            rep(j, i)
            {
                if (s.at(j) == 'G' && s.at(2 * i - j) == 'B')
                {
                    ans--;
                }
                if (s.at(j) == 'B' && s.at(2 * i - j) == 'G')
                {
                    ans--;
                }
            }
        }
        if (s.at(i) == 'G')
        {
            ans += blue.at(i) * (red.at(n - 1) - red.at(i)) + green.at(i) * (blue.at(n - 1) - blue.at(i));
            rep(j, i)
            {
                if (s.at(j) == 'R' && s.at(2 * i - j) == 'B')
                {
                    ans--;
                }
                if (s.at(j) == 'B' && s.at(2 * i - j) == 'R')
                {
                    ans--;
                }
            }
        }
        if (s.at(i) == 'B')
        {
            ans += green.at(i) * (red.at(n - 1) - red.at(i)) + green.at(i) * (red.at(n - 1) - red.at(i));
            rep(j, i)
            {
                if (s.at(j) == 'G' && s.at(2 * i - j) == 'R')
                {
                    ans--;
                }
                if (s.at(j) == 'R' && s.at(2 * i - j) == 'G')
                {
                    ans--;
                }
            }
        }
    }
    cout << ans << endl;
}
