using System;
using System.Collections.Generic;

namespace abc162
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();
            var total = 0L;
            var rFro = new List<int>();
            var bFro = new List<int>();
            var gFro = new List<int>();
            var rRev = new List<int>();
            var bRev = new List<int>();
            var gRev = new List<int>();
            var r = 0;
            var b = 0;
            var g = 0;
            for (var i = 0; i < s.Length; ++i)
            {
                switch (s[i])
                {
                    case 'R':
                        ++r;
                        break;
                    case 'B':
                        ++b;
                        break;
                    default:
                        ++g;
                        break;
                }
                rFro.Add(r);
                bFro.Add(b);
                gFro.Add(g);
                rRev.Add(0);
                bRev.Add(0);
                gRev.Add(0);
            }
            r = 0;
            b = 0;
            g = 0;
            for (var i = s.Length - 1; i >= 0; --i)
            {
                switch (s[i])
                {
                    case 'R':
                        ++r;
                        break;
                    case 'B':
                        ++b;
                        break;
                    default:
                        ++g;
                        break;
                }
                rRev[i] = r;
                bRev[i] = b;
                gRev[i] = g;
            }

            for (var c = 1; c < s.Length - 1; ++c)
            {
                //Console.WriteLine("Center {0}({1}) :", c, s[c]);
                switch (s[c])
                {
                    case 'R':
                        total += bFro[c - 1] * gRev[c + 1];
                        total += gFro[c - 1] * bRev[c + 1];
                        //Console.WriteLine(" Add {0}*{1} {2}*{3}", bFro[c - 1], gRev[c + 1], gFro[c - 1], bRev[c + 1]);
                        break;
                    case 'B':
                        total += rFro[c - 1] * gRev[c + 1];
                        total += gFro[c - 1] * rRev[c + 1];
                        //Console.WriteLine(" Add {0}*{1} {2}*{3}", rFro[c - 1], gRev[c + 1], gFro[c - 1], rRev[c + 1]);
                        break;
                    default:
                        total += rFro[c - 1] * bRev[c + 1];
                        total += bFro[c - 1] * rRev[c + 1];
                        //Console.WriteLine(" Add {0}*{1} {2}*{3}", bFro[c - 1], rRev[c + 1], rFro[c - 1], bRev[c + 1]);
                        break;
                }
                for (var div = 1; c - div >= 0 && c + div < s.Length; ++div)
                {
                    if (s[c - div] != s[c] && s[c] != s[c + div] && s[c - div] != s[c + div])
                    {
                        --total;
                        //Console.WriteLine(" Dec");
                    }
                }
                //Console.WriteLine(" Current " + total);
            }
            Console.WriteLine(total);
        }
    }
}


Measured memory_bytes: 27972