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

namespace abc162
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
            if (File.Exists("input.txt"))
            {
                Console.SetIn(new StreamReader("input.txt"));
            }
			solve_abc162D2();
            //List<int> test = new List<int>(){1, 2, 2, 2, 3, 4, 5, 6 ,7};
            //Console.WriteLine(binarySerachDown(test, 2));

			Console.Out.Flush();

        }

        /*
        https://atcoder.jp/contests/abc162/submissions/11816716
        */
        public static void solve_abc162D2()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            char[] s = Console.ReadLine().ToCharArray();
            int[,] cnt = new int[4005, 4];
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    cnt[i + 1, j] = cnt[i, j];
                }
                if (s[i] == 'R')
                {
                    s[i] = 'A';
                }
                else if (s[i] == 'G')
                {
                    s[i] = 'C';
                }
                cnt[i + 1, s[i] - 'A']++;
            }
            long ans = 0;
            for (int i = 0; i < n; i++)
            {
                for (int k = i + 1; k < n; k++)
                {
                    if (s[i] == s[k])
                    {
                        continue;
                    }
                    int other = 3 - (s[i] - 'A') - (s[k] - 'A');
                    ans += cnt[k, other] - cnt[i + 1, other];
                    int j = (i + k) / 2;
                    if (2 * j == i + k && s[j] - 'A' == other)
                    {
                        ans--;
                    }
                }
            }
            Console.WriteLine(ans);
        }

        public static void solve_abc162D()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string s = Console.ReadLine();
            List<int> rs = new List<int>();
            List<int> gs = new List<int>();
            List<int> bs = new List<int>();
            for (int i = 0; i < n; i++)
            {
                if (s[i] == 'R')
                {
                    rs.Add(i);
                }
                if (s[i] == 'G')
                {
                    gs.Add(i);
                }
                if (s[i] == 'B')
                {
                    bs.Add(i);
                }
            }
            long cnt = 0;
            for (int i = 0; i < n; i++)
            {
                for (int j = i + 1; j < n; j++)
                {
                    if ((s[i] == 'R' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'R'))
                    {
                        int idx = binarySerachDown(gs, j, j - i);
                        cnt += gs.Count - idx;
                    }
                    else if ((s[i] == 'R' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'R'))
                    {
                        int idx = binarySerachDown(bs, j, j - i);
                        cnt += bs.Count - idx;
                    }
                    else if ((s[i] == 'B' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'B'))
                    {
                        int idx = binarySerachDown(rs, j, j - i);
                        cnt += rs.Count - idx;
                    }
                }
            }
            Console.WriteLine(cnt);
        }
        
        public static int binarySerachUp(List<int> list, int x, int diff)
        {
            int l = 0;
            int h = list.Count;
            while (l < h)
            {
                int mid = (l + h) / 2;
                if (x >= list[mid])
                {
                    l = mid + 1;
                }
                else
                {
                    h = mid;
                }
            }
            return l;
        }        
        public static int binarySerachDown(List<int> list, int x, int diff)
        {
            int l = 0;
            int h = list.Count;
            while (l < h)
            {
                int mid = (l + h) / 2;
                if (x <= list[mid])
                {
                    h = mid;
                }
                else
                {
                    l = mid + 1;
                }
            }
            int ret = l;
            if (list[l] - x == diff)
            {
                if (l + 1 < list.Count)
                {
                    ret = l + 1;
                }
            }
            return ret;
        }

        public static void solve_abc162C()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int sum = 0;
            for (int i = 1; i <= n; i++)
            {
                for (int j = 1; j <= n; j++)
                {
                    for (int k = 1; k <= n; k++)
                    {
                        sum += gcd(i, gcd(j, k));
                    }
                }
            }

            Console.WriteLine(sum);
        }
        public static int gcd(int a, int b)
        {
            if (b == 0)
            {
                return a;
            }
            else
            {
                return gcd(b, a % b);
            }
        }

        public static void solve_abc162B()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            long sum = 0;
            for (int i = 1; i <= n; i++)
            {
                if (i % 3 != 0 && i % 5 != 0)
                {
                    sum += i;
                }
            }
            Console.WriteLine(sum);
        }

        public static void solve_abc162A()
        {
            string s = Console.ReadLine();
            Console.WriteLine(s.Contains("7") ? "Yes" : "No");
        }
    }
}
