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

public class AtCoderD
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();
        string s = sc.Next();

        int[] sumR = new int[n];
        int[] sumG = new int[n];
        int[] sumB = new int[n];

        for (int i = 0; i < n; i++)
        {
            if (i == 0)
            {
                sumR[i] = 0;
                sumG[i] = 0;
                sumB[i] = 0;
            }
            else
            {
                sumR[i] = sumR[i - 1];
                sumG[i] = sumG[i - 1];
                sumB[i] = sumB[i - 1];
            }
            if (s[i] == 'R')
            {
                sumR[i]++;
            }
            else if (s[i] == 'G')
            {
                sumG[i]++;
            }
            else
            {
                sumB[i]++;
            }
        }

        long answer = 0;

        for (int i = 0; i < n; i++)
        {
            char strI = s[i];
            for (int j = i + 1; j < n - 1; j++)
            {
                char strJ = s[j];
                if (strI == strJ)
                {
                    continue;
                }

                char strK;
                int ngIndex = 2 * j - i;
                if (strI != 'R' && strJ != 'R')
                {
                    strK = 'R';
                    answer += sumR[n - 1] - sumR[j];
                    if (ngIndex < n && s[ngIndex] == 'R')
                    {
                        answer--;
                    }
                }
                else if (strI != 'G' && strJ != 'G')
                {
                    strK = 'G';
                    answer += sumG[n - 1] - sumG[j];
                    if (ngIndex < n && s[ngIndex] == 'G')
                    {
                        answer--;
                    }
                }
                else
                {
                    strK = 'B';
                    answer += sumB[n - 1] - sumB[j];
                    if (ngIndex < n && s[ngIndex] == 'B')
                    {
                        answer--;
                    }
                }
            }
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 27544