using System;
using static System.Console;
using System.Collections.Generic;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = long.Parse(ReadLine());
            char[] S = ReadLine().ToCharArray();
            var rgb = new Dictionary<char,long> { {'R',0},{'G',0 },{'B',0 }};
            int tmp = 0;

            for(long i = 0; i < N; i ++)
            {
                rgb[S[i]] += 1;

                for(long j = i + 1; j < N; j++)
                {
                    if(S[i] != S[j] && j * 2 - i < N)
                    {
                        if(S[j * 2 - i] != S[i] && S[j * 2 - i] != S[j])
                        {
                            tmp += 1;
                        }
                    }
                }
            }
            WriteLine(rgb['R'] * rgb['G'] * rgb['B'] - tmp);
        }
    }
}
