using System;
using System.Linq;
using System.Collections.Generic;

namespace ABC162D
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var input = Console.ReadLine().ToCharArray();

            var acumR = new int[n];
            var acumG = new int[n];
            var acumB = new int[n];

            acumR[n - 1] = 0;
            acumG[n - 1] = 0;
            acumB[n - 1] = 0;

            for (int i = n - 2; i >= 0; i--)
            {
                switch (input[i + 1])
                {
                    case 'R':
                        acumR[i] = acumR[i + 1] + 1;
                        acumG[i] = acumG[i + 1];
                        acumB[i] = acumB[i + 1];
                        break;
                    case 'G':
                        acumR[i] = acumR[i + 1];
                        acumG[i] = acumG[i + 1] + 1;
                        acumB[i] = acumB[i + 1];
                        break;
                    case 'B':
                        acumR[i] = acumR[i + 1];
                        acumG[i] = acumG[i + 1];
                        acumB[i] = acumB[i + 1] + 1;
                        break;
                }
            }

            long sum = 0;
            for (int i = 0; i < n; i++)
            {
                switch (input[i])
                {
                    case 'R':
                        for (int j = i + 1; j < n; j++)
                        {
                            if(input[j] == 'G')
                            {
                                sum += acumB[j];
                            }
                            if(input[j] == 'B')
                            {
                                sum += acumG[j];
                            }

                            int bad = j + j - i;
                            if(bad < n && input[j] != 'R' && input[bad] != 'R' && input[j] != input[bad])
                            {
                                sum--;
                            }
                        }
                        break;
                    case 'G':
                        for (int j = i + 1; j < n; j++)
                        {
                            if (input[j] == 'B')
                            {
                                sum += acumR[j];
                            }
                            if (input[j] == 'R')
                            {
                                sum += acumB[j];
                            }

                            int bad = j + j - i;
                            if (bad < n && input[j] != 'G' && input[bad] != 'G' && input[j] != input[bad])
                            {
                                sum--;
                            }
                        }
                        break;
                    case 'B':
                        for (int j = i + 1; j < n; j++)
                        {
                            if (input[j] == 'R')
                            {
                                sum += acumG[j];
                            }
                            if (input[j] == 'G')
                            {
                                sum += acumR[j];
                            }

                            int bad = j + j - i;
                            if (bad < n && input[j] != 'B' && input[bad] != 'B' && input[j] != input[bad])
                            {
                                sum--;
                            }
                        }
                        break;
                }
            }

            Console.WriteLine($"{sum}");
        }
    }
}


Measured memory_bytes: 27480