using System;
using System.Text;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using static System.Array;
using System.Globalization;

namespace ConsoleApp2
{
    class Program
    {
        static long K;
        static long N;
        static long[] A;
        static void Main(string[] args)
        {
            //var UV = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();

            var N = long.Parse(Console.ReadLine());
            var S = Console.ReadLine();
            var R = new long[N];
            var G = new long[N];
            var B = new long[N];

            for (int i = (int)N-1; i >= 0; i--)
            {
                if (i < N - 1)
                {
                    R[i] = R[i + 1];
                    G[i] = G[i + 1];
                    B[i] = B[i + 1];
                }
                if (S[i] == 'R')
                {
                    R[i]++;
                }else if(S[i] == 'G')
                {
                    G[i]++;
                }
                else if (S[i] == 'B')
                {
                    B[i]++;
                }
                
            }
            long ans = 0;
            for (int i = 0; i < N; i++)
            {
                if (S[i] == 'R')
                {
                    //RGB
                    for (int j = i+1; j < N; j++)
                    {
                        if (S[j] == 'G')
                        {
                            ans += (2 * j - i < N && S[2 * j - i] == 'B') ? B[j] - 1 : B[j];
                        }
                    }
                    //RBG
                    for (int j = i + 1; j < N; j++)
                    {
                        if (S[j] == 'B')
                        {
                            ans += (2 * j - i < N && S[2 * j - i] == 'G') ? G[j] - 1 : G[j];
                        }
                    }
                }
                else if (S[i] == 'G')
                {
                    //GBR
                    for (int j = i + 1; j < N; j++)
                    {
                        if (S[j] == 'B')
                        {
                            ans += (2 * j - i < N && S[2 * j - i] == 'R') ? R[j] - 1 : R[j];
                        }
                    }
                    //GRB
                    for (int j = i + 1; j < N; j++)
                    {
                        if (S[j] == 'R')
                        {
                            ans += (2 * j - i < N && S[2 * j - i] == 'B') ? B[j] - 1 : B[j];
                        }
                    }
                }
                else if (S[i] == 'B')
                {
                    //BRG
                    for (int j = i + 1; j < N; j++)
                    {
                        if (S[j] == 'R')
                        {
                            ans += (2 * j - i < N && S[2 * j - i] == 'G') ? G[j] - 1 : G[j];
                        }
                    }
                    //BGR
                    for (int j = i + 1; j < N; j++)
                    {
                        if (S[j] == 'G')
                        {
                            ans += (2 * j - i < N && S[2 * j - i] == 'R') ? R[j] - 1 : R[j];
                        }
                    }
                }
            }

            Console.WriteLine(ans);

        }
    }
}


Measured memory_bytes: 17644