Language: C

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");
        }
    }
}


Compiler output:
main.c:1:1: error: unknown type name 'using'
    1 | using System;
      | ^~~~~
main.c:2:1: error: unknown type name 'using'
    2 | using System.IO;
      | ^~~~~
main.c:2:13: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
    2 | using System.IO;
      |             ^
main.c:3:1: error: unknown type name 'using'
    3 | using System.Linq;
      | ^~~~~
main.c:3:13: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
    3 | using System.Linq;
      |             ^
main.c:4:1: error: unknown type name 'using'
    4 | using System.Collections.Generic;
      | ^~~~~
main.c:4:13: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
    4 | using System.Collections.Generic;
      |             ^
main.c:5:1: error: unknown type name 'using'
    5 | using System.Text;
      | ^~~~~
main.c:5:13: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
    5 | using System.Text;
      |             ^
main.c:6:1: error: unknown type name 'using'
    6 | using System.Numerics;
      | ^~~~~
main.c:6:13: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
    6 | using System.Numerics;
      |             ^
main.c:8:1: error: unknown type name 'namespace'
    8 | namespace abc162
      | ^~~~~~~~~
main.c:9:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
    9 | {
      | ^