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

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var n = Console.ReadLine().ToInt();
		var s = Console.ReadLine();
		
		var pos = new Dictionary<char, List<int>>();
		pos.Add('R', new List<int>());
		pos.Add('G', new List<int>());
		pos.Add('B', new List<int>());
		
		var posArray = new Dictionary<char, int[]>();
		
		for(int i = 0; i < n; i++)
			pos[s[i]].Add(i);
		long wa = 0;
		
		if(pos['R'].Count == 0 || pos['G'].Count == 0 || pos['B'].Count == 0)
		{
			Console.WriteLine(0);
			return;
		}
		posArray.Add('R', pos['R'].ToArray());
		posArray.Add('G', pos['G'].ToArray());
		posArray.Add('B', pos['B'].ToArray());
		
		var hash = new HashSet<long>();
		for(int i = 0; i < n; i++)
		{
			for(int j = i+1; j < n; j++)
			{
				if(s[i]==s[j])
					continue;
				char kchar = "RGB".Replace(s[i].ToString(), "").Replace(s[j].ToString(), "")[0];
				
				int up1 = UpperBound(posArray[kchar], j);
				int l = posArray[kchar].Length ;
				int size = l - up1;
				if(Array.BinarySearch(posArray[kchar], j + (j-i)) >= up1)
					size--;
				wa += size;
				/*
				for(int k = up1; k < posArray[kchar].Length; k++)
				{
					var q = posArray[kchar][k];
					if(j - i == q - j)// || hash.Contains(i * 5000 * 5000 + j * 5000 + q))
						continue;
					//hash.Add(i * 5000 * 5000 + j * 5000 + q);
					//wa++;
				}
				*/
				/*
				foreach(var q in posArray[kchar])
				{
				}
				
				int up1 = UpperBound(posArray[kchar],j);
				int up = LowerBound(posArray[kchar],j + (j-i)-1);
				int up3 = UpperBound(posArray[kchar],j + (j-i)-1);
				
				int l = posArray[kchar].Length ;
				
				//l - up1 + up + up3;
				if(up < l && up1 < l)
					wa += l - up1 + up + up3 - 1;
				Console.WriteLine("{0} {1} {2} {3} {4} [{5}] {6}", i, j, up1, up, up3, kchar, l - up1 + up + up3);
				for(int i = 0; i < n; i++)
				{
						
				}
				*/
									
			}
		
		}
		
		Console.WriteLine(wa);
		/*
		wa = 0;
		
		foreach(var r in pos['R'])
		{
			foreach(var g in pos['G'])
			{
				if(r < g)
				{
					
				}
				//q[0]より前にbがある
				
				foreach(var b in pos['B'])
				{
					var q = new int[]{r, g, b};
					Array.Sort(q);
				
					if(q[0] < q[1] && q[1] < q[2] && q[1] - q[0] != q[2] - q[1])
					{
						wa++;
					}
				}
				
			}
		}
		
		Console.WriteLine(wa);
		*/
	}

	public static int UpperBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer)
	{
	    int low = start;
	    int high = end;
	    int mid;
	    while (low < high)
	    {
	        mid = ((high - low) >> 1) + low;
	        if (comparer.Compare(arr[mid], value) <= 0)
	            low = mid + 1;
	        else
	            high = mid;
	    }
	    return low;
	}

	//引数省略のオーバーロード
	public static int UpperBound<T>(T[] arr, T value)
	{
	    return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default);
	}
	
	
public static int LowerBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer)
{
    int low = start;
    int high = end;
    int mid;
    while (low < high)
    {
        mid = ((high - low) >> 1) + low;
        if (comparer.Compare(arr[mid], value) < 0)
            low = mid + 1;
        else
            high = mid;
    }
    return low;
}

//引数省略のオーバーロード
public static int LowerBound<T>(T[] arr, T value) where T : IComparable
{
    return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default);
}

	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

Measured memory_bytes: 41216