using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static ABC162D.Input;

namespace ABC162D
{
    static class Input
    {
        // Type Convert
        private static Func<string, T> C<T>()
        {
            Type t = typeof(T);
            if (t == typeof(string)) return _ => (T) (object) _;
            if (t == typeof(int)) return _ => (T) (object) int.Parse(_);
            if (t == typeof(long)) return _ => (T) (object) long.Parse(_);
            if (t == typeof(double)) return _ => (T) (object) double.Parse(_);
            if (t == typeof(char)) return _ => (T) (object) _[0];
            if (t == typeof(string[])) return _ => (T) (object) _.Split(' ');
            if (t == typeof(int[])) return _ => (T) (object) Cast<int>()(_);
            if (t == typeof(long[])) return _ => (T) (object) Cast<long>()(_);
            if (t == typeof(double[])) return _ => (T) (object) Cast<double>()(_);
            if (t == typeof(char[])) return _ => (T) (object) Cast<char>()(_);
            throw new NotSupportedException(t + "is not supported.");
            Func<string, T1[]> Cast<T1>() => _ => _.Split(' ').Select(C<T1>()).ToArray();
        }

        private static T C<T>(string s) => C<T>()(s);

        private static string String() => Console.ReadLine();
        private static string[] Split() => String().Split(' ');
        private static string[] String(long rowNumber) => new bool[rowNumber].Select(_ => String()).ToArray();

        private static (T1, T2) In<T1, T2>(string[] v) => (C<T1>(v[0]), C<T2>(v[1]));
        private static (T1, T2, T3) In<T1, T2, T3>(string[] v) => (C<T1>(v[0]), C<T2>(v[1]), C<T3>(v[2]));

        private static (T1, T2, T3, T4) In<T1, T2, T3, T4>(string[] v) =>
            (C<T1>(v[0]), C<T2>(v[1]), C<T3>(v[2]), C<T4>(v[3]));

        private static (T1, T2, T3, T4, T5) In<T1, T2, T3, T4, T5>(string[] v) =>
            (C<T1>(v[0]), C<T2>(v[1]), C<T3>(v[2]), C<T4>(v[3]), C<T5>(v[4]));

        private static (T1, T2, T3, T4, T5, T6) In<T1, T2, T3, T4, T5, T6>(string[] v) =>
            (C<T1>(v[0]), C<T2>(v[1]), C<T3>(v[2]), C<T4>(v[3]), C<T5>(v[4]), C<T6>(v[5]));

        /* いくつかの変数を受け取る */
        public static void Cin<T>(out T a) => a = C<T>(String());
        public static void Cin<T1, T2>(out T1 a, out T2 b) => (a, b) = In<T1, T2>(Split());

        public static void Cin<T1, T2, T3>(out T1 a, out T2 b, out T3 c) => (a, b, c) = In<T1, T2, T3>(Split());

        public static void Cin<T1, T2, T3, T4>(out T1 a, out T2 b, out T3 c, out T4 d) =>
            (a, b, c, d) = In<T1, T2, T3, T4>(Split());

        public static void Cin<T1, T2, T3, T4, T5>(out T1 a, out T2 b, out T3 c, out T4 d, out T5 e) =>
            (a, b, c, d, e) = In<T1, T2, T3, T4, T5>(Split());

        public static void Cin<T1, T2, T3, T4, T5, T6>(out T1 a, out T2 b, out T3 c, out T4 d, out T5 e, out T6 f) =>
            (a, b, c, d, e, f) = In<T1, T2, T3, T4, T5, T6>(Split());

        /* 1行に書かれた配列を受け取る */
        public static void Cin<T>(out T[] a) => a = C<T[]>(String());

        /* n行に書かれたいくつかの配列を受け取る */
        public static void Cin<T>(long n, out T[] l) => l = String(n).Select(C<T>()).ToArray();

        public static void Cin<T1, T2>(long n, out T1[] l1, out T2[] l2)
        {
            (l1, l2) = (new T1[n], new T2[n]);
            for (int i = 0; i < n; i++) Cin(out l1[i], out l2[i]);
        }

        public static void Cin<T1, T2, T3>(long n, out T1[] l1, out T2[] l2, out T3[] l3)
        {
            (l1, l2, l3) = (new T1[n], new T2[n], new T3[n]);
            for (int i = 0; i < n; i++) Cin(out l1[i], out l2[i], out l3[i]);
        }

        public static void Cin<T1, T2, T3, T4>(long n, out T1[] l1, out T2[] l2, out T3[] l3, out T4[] l4)
        {
            (l1, l2, l3, l4) = (new T1[n], new T2[n], new T3[n], new T4[n]);
            for (int i = 0; i < n; i++) Cin(out l1[i], out l2[i], out l3[i], out l4[i]);
        }

        /* T型の行列を受け取る */
        public static void Cin<T>(long h, out T[][] map) => map = String(h).Select(C<T[]>()).ToArray();
    }

    class Program
    {
        public static void Main(string[] args)
        {
            StreamWriter streamWriter = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            Console.SetOut(streamWriter);
            new Solver().Solve();
            Console.Out.Flush();
        }

        public static void Debug()
        {
            new Solver().Solve();
        }
    }

    class Solver
    {
        private long n;

        public void Solve()
        {
            Cin(out n);
            Cin(out string s);
            var r = new List<long>();
            var g = new List<long>();
            var b = new List<long>();
            var rs = new HashSet<long>();
            var gs = new HashSet<long>();
            var bs = new HashSet<long>();
            for (int i = 0; i < n; i++)
            {
                if (s[i] == 'R') r.Add(i);
                if (s[i] == 'G') g.Add(i);
                if (s[i] == 'B') b.Add(i);
                if (s[i] == 'R') rs.Add(i);
                if (s[i] == 'G') gs.Add(i);
                if (s[i] == 'B') bs.Add(i);
            }

            long ans = 0;
            ans += calc(r, g, bs, b);
            ans += calc(g, r, bs, b);
            ans += calc(r, b, gs, g);
            ans += calc(b, r, gs, g);
            ans += calc(g, b, rs, r);
            ans += calc(b, g, rs, r);
            Console.WriteLine(ans);
        }

        long calc(List<long> a, List<long> b, HashSet<long> cs, List<long> c)
        {
            long ans = 0;
            for (int ai = 0; ai < a.Count; ai++)
            {
                for (int bi = 0; bi < b.Count; bi++)
                {
                    if (b[bi] < a[ai]) continue;

                    long index = Search((int) b[bi]);
                    if (index < 0 || index == c.Count) continue;
                    long count = c.Count - index;
                    if (cs.Contains(2 * b[bi] - a[ai]) && count > 0)
                    {
                        ans += count - 1;
                    }
                    else
                    {
                        ans += count;
                    }
                }
            }

            return ans;

            long Search(int min)
            {
                int ng = -1;
                int ok = c.Count;

                while (Math.Abs(ok - ng) > 1)
                {
                    int mid = (ok + ng) / 2;
                    if (IsOK(mid, min)) ok = mid;
                    else ng = mid;
                }

                return ok;
            }

            bool IsOK(int key, long min)
            {
                return c[key] >= min;
            }
        }
    }
}

Measured memory_bytes: 28184