#include <array>
#include <iostream>
#include <string>

int N;
std::string S;

std::array<int, 4005> sumR, sumG, sumB;

int main()
{
    std::cin >> N;
    std::cin >> S;

    sumR.fill(0);
    sumG.fill(0);
    sumB.fill(0);

    for (int i = 1; i <= N; ++i)
    {
        auto c = S[i - 1];

        sumR[i] = sumR[i - 1];
        sumG[i] = sumG[i - 1];
        sumB[i] = sumB[i - 1];

        if (c == 'R')
            sumR[i]++;
        else if (c == 'G')
            sumG[i]++;
        else if (c == 'B')
            sumB[i]++;
    }

    int ans = 0;
    for (int j = 2; j <= N - 1; ++j)
    {
        for (int k = j + 1; k <= N; ++k)
        {
            auto cj = S[j - 1];
            auto ck = S[k - 1];
            auto ieq = 2 * j - k - 1;
            if (cj == ck)
                continue;
            if ((cj == 'R' && ck == 'G') || (cj == 'G' && ck == 'R'))
            {
                ans += sumB[j - 1];
                if (ieq >= 0 && S[ieq] == 'B')
                {
                    ans--;
                }
            }
            else if ((cj == 'R' && ck == 'B') || (cj == 'B' && ck == 'R'))
            {
                ans += sumG[j - 1];
                if (ieq >= 0 && S[ieq] == 'G')
                {
                    ans--;
                }
            }
            else if ((cj == 'B' && ck == 'G') || (cj == 'G' && ck == 'B'))
            {
                ans += sumR[j - 1];
                if (ieq >= 0 && S[ieq] == 'R')
                {
                    ans--;
                }
            }
        }
    }

    std::cout << ans << std::endl;
    return 0;
}
