using System;
using System.Collections;
using System.Collections.Generic;

namespace 練習問題
{
    class Program {
        static void Main(string[] args) {
            // var sw =z new System.Diagnostics.Stopwatch();
            // sw.Start();
            List<int> pattern = new List<int>();
            int n = 0;
            string s = ""; 
            long result = 0;
            // Si != Sj && Si != Sk && Sj != Sk
            // j - i != k - j
            debug Debug = new debug();
            if (args.Length == 0){
                Debug.FlagFalse();
                /*
                string[] input = Console.ReadLine().Split(' ');
                int a = int.Parse(input[0]);
                int b = int.Parse(input[1]);
                */
                n = int.Parse(Console.ReadLine());
                s = Console.ReadLine();
                // string d = Console.ReadLine();

                //string[] input = Console.ReadLine().Split(' ');
            } else {
                Debug.FlagTrue();
                if (args[0] == "1"){
                    pattern.Add(4);
                    pattern.Add(3);
                    n = pattern[0];
                    s = "RRGB";
                } else if (args[0] == "2"){
                    pattern.Add(39);
                    pattern.Add(4);
                    n = pattern[0];
                    s = "RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB";
                } else if (args[0] == "3"){
                    n = 702;
                    s = "RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBBRBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBBRBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBBRBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBBRBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBBRBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBBRBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBBRBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBBRBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBBRBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBBRBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBBRBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBBRBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBBRBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBBRBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBBRBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBBRBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBBRBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB";
                } else {
                    n = 3;
                    s = "RGBR";
                }
            }
            List<int> r = new List<int>();
            List<int> g = new List<int>();
            List<int> b = new List<int>();
            for (int i = 0; i < n; i++) {
                if (s.Substring(i,1) == "R"){
                    r.Add(i);
                } else if (s.Substring(i,1) == "G"){
                    g.Add(i);
                } else {
                    b.Add(i);
                }
            }
            result = (long)r.Count * (long)g.Count * (long)b.Count;
            for (int i = 0; i < n; i++) {
                for (int j = i + 1; j < n; j++) {
                    var k = j + (j - i);
                    if (k >= n){
                        continue;
                    } else if (s.Substring(i,1) != s.Substring(j,1)
                               && s.Substring(i,1) != s.Substring(k,1)
                               && s.Substring(j,1) != s.Substring(k,1)){
                        result--;
                    }
                }
            }
            // var sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false};
            // Console.SetOut(sw);
            /*何らかの出力処理*/
            Console.WriteLine(result);
            // Console.Out.Flush();
            
            // sw.Stop();
            // Console.WriteLine("■処理Aにかかった時間");
            // TimeSpan ts = sw.Elapsed;
            // Console.WriteLine($"　{ts}");
        }
        
        static int intPow(int target,int kaisu) {
            int startTarget = target;
            for (int i = 1; i < kaisu; i++)
            {
                target *= startTarget;
            }
            return target;
        }

        static void bubble_sort(List<List<int>> a) {
            int count=0;
            for (int i = 0; i < a.Count; i++) {
                for (int j = 0; j < a.Count-i-1; j++) {
                    // if (a[j] == a[a.Count - 1]){
                    //     continue;
                    // }
                    count++;
                    if (a[j][1] > a[j+1][1]){
                        int localsave = 0;
                        localsave = a[j+1][1];
                        a[j+1][1] = a[j][1];
                        a[j][1] = localsave;
                        localsave = a[j][0];
                        a[j][0] = a[j+1][0];
                        a[j+1][0] = localsave;
                    }
                }
                //debug(a,"途中" + i);
            }
            // debug(a,"result");
            //Console.WriteLine("回数"+count);
            for (int i = 0; i < a.Count; i++)
            {
                Console.WriteLine(a[i][0]+" "+a[i][1]);
            }
        }
        /* 標準入力と標準出力が使えるかのチェック
        static void echo() {
            string echotest = Console.ReadLine();
            Console.WriteLine(echotest);
        }

        static void HelloWorld(){
            Console.WriteLine("Hello World!");
        }
        */
    }

    public class debug{ //宣言時は、「 debug Debug = new debug(); 」推奨
        bool debug_flag = true;
        public void Log(string str){
            if (debug_flag == true){
                Console.WriteLine(str);
            }
        }
        public void Log(int str){
            if (debug_flag == true){
                Console.WriteLine(str);
            }
        }
        public void Log(float str){
            if (debug_flag == true){
                Console.WriteLine(str);
            }
        }
        public void Log(object obj){
            if (debug_flag == true){
                Console.WriteLine(obj);
            }
        }

        public void Log(int[] arr){
            if (debug_flag == true){
                Console.WriteLine(string.Join(",", arr));
            }
        }
        public void Log(string[] arr){
            if (debug_flag == true){
                Console.WriteLine(string.Join(",", arr));
            }
        }
        public void Log(List<int> arr){
            if (debug_flag == true){
                string shuturyoku = "";
                for (int i = 0; i < arr.Count; i++) {
                    shuturyoku += arr[i] + ",";
                }
                Console.WriteLine(shuturyoku.TrimEnd(','));
            }
        }

        public void Log(List<string> arr){
            if (debug_flag == true){
                string shuturyoku = "";
                for (int i = 0; i < arr.Count; i++) {
                    shuturyoku += arr[i] + ",";
                }
                Console.WriteLine(shuturyoku.TrimEnd(','));
            }
        }

        public void Log(List<float> arr){
            if (debug_flag == true){
                string shuturyoku = "";
                for (int i = 0; i < arr.Count; i++) {
                    shuturyoku += arr[i] + ",";
                }
                Console.WriteLine(shuturyoku.TrimEnd(','));
            }
        }
        public void Log(){
            if (debug_flag == true){
                Console.WriteLine("アタイイレナサイ");
            }
        }
        public void FlagFalse(){
            debug_flag = false;
        }
        public void FlagTrue(){
            debug_flag = true;
        }
    }
}


Measured memory_bytes: 40624