#include <iostream>
#include <string>
#include <vector>

std::vector<int> vec;

int rem(int a, int b)
{
    int r;
    for (int i = 0; i < 3; ++i)
    {
        if (i != a && i != b)
            r = i;
    }

    return r;
}

int main()
{

    int n;

    std::cin >> n;

    long long int r = 0, g = 0, b = 0;

    for (int i = 0; i < n; ++i)
    {
        char ch;
        std::cin >> ch;
        if (ch == 'R')
        {
            vec.push_back(0);
            ++r;
        }
        else if (ch == 'G')
        {
            vec.push_back(1);
            ++g;
        }
        else
        {
            vec.push_back(2);
            ++b;
        }
    }

    long long int sum = r * g * b;

    for (int i = 0; i < n; ++i)
    {
        for (int j = i; j * 2 - i < n; ++j)
        {
            int k = j * 2 - i;

            if (vec[i] != vec[j] && rem(vec[i], vec[j]) == vec[k])
                --sum;
        }
    }

    std::cout << sum << std::endl;

    return 0;
}