#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<climits>
#include<cmath>
#include<sstream>
#include<iomanip>
#include <map>
#include <stack>

struct max_min
{
    int64_t max = 0;
    int64_t min = 0;
};

const int64_t cc = pow( 10, 9 ) + 7;
//std::cout<< std::fixed << std::setprecision(10) << ( double )( max ) / 2;
bool sort_pair( std::pair< int64_t, int64_t > origin, std::pair< int64_t, int64_t > another )
{
    return origin.first < another.first;
}

int64_t
gcd( int64_t x,  int64_t y )
{
     int64_t min = ( x < y ) ? x : y;
     int64_t max = ( x < y ) ? y : x;
    
    while( 1 )
    {
         int64_t mod = max % min;
        
        if( mod == 0 )
        {
            return min;
        }

        max = min;
        min = mod;
    }
    
    return 1;
}

int main()
{
    std::string word;
    std::string w = "No";
    int64_t a,b,c,d,e,f;
    std::cin>> a;
    std::cin>> word;

    std::vector< int64_t > rgb( 3, 0 );
    std::vector< int64_t > rgb_mainasu( 3, 0 );

    for( int i = 0; i < a; i++ )
    {
        if( word[i] == 'R' )
        {
            rgb[0] += 1;
        }
        else if( word[i] == 'G' )
        {
            rgb[1] += 1;
        }
        else if( word[i] == 'B' )
        {
            rgb[2] += 1;
        }
    }

    b = 0;
    c = 0;
    char c1,c2;
    
    for( int i = 0; i < a; i++ )
    {
        if( rgb[0] == 0
            || rgb[1] == 0
            || rgb[2] == 0 )
        {
            break;
        }
        
        if( word[i] == 'R' )
        {
            rgb[0] -= 1;
            c1 = 'G';
            c2 = 'B';
        }
        else if( word[i] == 'G' )
        {
            rgb[1] -= 1;
            c1 = 'R';
            c2 = 'B';
        }
        else if( word[i] == 'B' )
        {
            rgb[2] -= 1;
            c1 = 'R';
            c2 = 'G';
        }

        std::vector< int64_t > instance = rgb;
        
        for( int r = i + 1; r < a; r++ )
        {            
            if( ( word[r] == c1
                  || word[r] == c2 )
                && r + 1 < a )
            {
                b = r - i;

                if( word[r] == 'R' )
                {
                    instance[0] -= 1;
                    
                    if( word[i] == 'G' )
                    {
                        c += instance[2];

                        if( r + b < a
                            && word[r+b] == 'B' )
                        {
                            c -= 1;
                        }
                    }
                    else if( word[i] == 'B' )
                    {
                        c += instance[1];

                        if( r + b < a
                            && word[r+b] == 'G' )
                        {
                            c -= 1;
                        }
                    }
                }
                else if( word[r] == 'G' )
                {
                    instance[1] -= 1;
                    
                    if( word[i] == 'R' )
                    {
                        c += instance[2];

                        if( r + b < a
                            && word[r+b] == 'B' )
                        {
                            c -= 1;
                        }
                    }
                    else if( word[i] == 'B' )
                    {
                        c += instance[0];

                        if( r + b < a
                            && word[r+b] == 'R' )
                        {
                            c -= 1;
                        }
                    }               
                }
                else if( word[r] == 'B' )
                {
                    instance[2] -= 1;
                    
                    if( word[i] == 'G' )
                    {
                        c += instance[0];

                        if( r + b < a
                            && word[r+b] == 'R' )
                        {
                            c -= 1;
                        }
                    }
                    else if( word[i] == 'R' )
                    {
                        c += instance[1];

                        if( r + b < a
                            && word[r+b] == 'G' )
                        {
                            c -= 1;
                        }
                    }                    
                }
            }
        }
    }

    std::cout<< c;
}


Measured memory_bytes: 3640