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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var s = Console.ReadLine().Trim();

        var t = s.Select(x => x == 'R' ? 0 : x == 'G' ? 1 : 2).ToArray();

        var sum = new int[3][];
        for (int i = 0; i < sum.Length; ++i)
        {
            sum[i] = new int[t.Length + 1];
        }
        for (int i = 0; i < t.Length; ++i)
        {
            for (int j = 0; j < sum.Length; ++j)
            {
                sum[j][i + 1] = sum[j][i];
            }
            ++sum[t[i]][i + 1];
        }

        var count = 0L;
        for (int i = 0; i < t.Length; ++i)
        {
            for (int j = i + 1; j < t.Length; ++j)
            if (s[i] != s[j])
            {
                // (0, 1) -> 2, (1, 2) -> 0, (2, 0) -> 1
                var c = sum.Length - (t[i] + t[j]);
                var k = j + (j - i);
                count += sum[c].Last() - sum[c][j + 1] - (k < t.Length && t[k] == c ? 1 : 0);
            }
        }

        Console.WriteLine(count);
    }
}
