using System;
using System.Collections.Generic;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            int N = int.Parse(line);
            line = Console.ReadLine();
            int sum = 0;

            var listR = new List<int>();
            var listG = new List<int>();
            var listB = new List<int>();

            // R[n]の後ろにあるBは何個
            var listRB = new Dictionary<int, int>();
            var listRG = new Dictionary<int, int>();
            var listBG = new Dictionary<int, int>();
            var listBR = new Dictionary<int, int>();
            var listGR = new Dictionary<int, int>();
            var listGB = new Dictionary<int, int>();

            for (int i = 0; i < N; i++)
            {
                if (line[i] == 'R') listR.Add(i);
                else if(line[i] == 'G') listG.Add(i);
                else listB.Add(i);
            }
            int beforeA = 0;
            int beforeB = 0;
            for (int i = 0; i < listR.Count; i++)
            {
                for (int j = beforeA; j < listB.Count; j++)
                {
                    if (listR[i] < listB[j])
                    {
                        beforeA = j;
                        listRB.Add(i, listB.Count - j);
                        break;
                    }
                }
                for (int j = beforeB; j < listG.Count; j++)
                {
                    if (listR[i] < listG[j])
                    {
                        beforeB = j;
                        listRG.Add(i, listG.Count - j);
                        break;
                    }
                }
            }
            beforeA = 0;
            beforeB = 0;
            for (int i = 0; i < listG.Count; i++)
            {
                for (int j = beforeA; j < listB.Count; j++)
                {
                    if (listG[i] < listB[j])
                    {
                        beforeA = j;
                        listGB.Add(i, listB.Count - j);
                        break;
                    }
                }
                for (int j = beforeB; j < listR.Count; j++)
                {
                    if (listG[i] < listR[j])
                    {
                        beforeB = j;
                        listGR.Add(i, listR.Count - j);
                        break;
                    }
                }
            }
            beforeA = 0;
            beforeB = 0;
            for (int i = 0; i < listB.Count; i++)
            {
                for (int j = beforeA; j < listR.Count; j++)
                {
                    if (listB[i] < listR[j])
                    {
                        beforeA = j;
                        listBR.Add(i, listR.Count - j);
                        break;
                    }
                }
                for (int j = beforeB; j < listG.Count; j++)
                {
                    if (listB[i] < listG[j])
                    {
                        beforeB = j;
                        listBG.Add(i, listG.Count - j);
                        break;
                    }
                }
            }

            for (int i = 0; i < N; i++)
            {
                if (line[i] == 'R')
                {
                    for (int j = listB.Count - 1; j >= 0; j--)
                    {
                        if (listB[j] < i) break;
                        if (listBG.ContainsKey(j))
                            sum += listBG[j];
                    }
                    for (int j = listG.Count - 1; j >= 0; j--)
                    {
                        if (listG[j] < i) break;
                        if (listGB.ContainsKey(j))
                            sum += listGB[j];
                    }
                }
                else if (line[i] == 'G')
                {
                    for (int j = listB.Count - 1; j >= 0; j--)
                    {
                        if (listB[j] < i) break;
                        if (listBR.ContainsKey(j))
                            sum += listBR[j];
                    }
                    for (int j = listR.Count - 1; j >= 0; j--)
                    {
                        if (listR[j] < i) break;
                        if (listRB.ContainsKey(j))
                            sum += listRB[j];
                    }
                }
                else if (line[i] == 'B')
                {
                    for (int j = listG.Count - 1; j >= 0; j--)
                    {
                        if (listG[j] < i) break;
                        if (listGR.ContainsKey(j))
                            sum += listGR[j];
                    }
                    for (int j = listR.Count - 1; j >= 0; j--)
                    {
                        if (listR[j] < i) break;
                        if (listRG.ContainsKey(j))
                            sum += listRG[j];
                    }
                }
            }
            //拾ってはいけないパターンだけ削る
            long minus = 0;
            for (int i = 1; i <= N / 2; i++)
            {
                for (int j = 0; j < N - i * 2; j++)
                {
                    if (line[j] != line[j + i] && line[j + i] != line[j + i + i] && line[j] != line[j + i + i]) minus++;
                }
            }
            Console.WriteLine((long)listR.Count * (long)listG.Count * (long)listB.Count - minus);
            //Console.WriteLine(sum-minus);
        }

    }
}


Measured memory_bytes: 28072