package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner()

	n := sc.ReadInt()
	s := sc.ReadString()

	if n < 3 {
		fmt.Println(0)
		return
	}

	rgbIndices := make([]rgbNums, n)
	var nums [3][4000]int
	var rgbSize rgbNums
	{
		rgb := rgbNums{}
		for i := range rgbIndices {
			c := s[i]
			if c == 'R' {
				nums[0][rgb.r] = i
				rgb.r++
			} else if c == 'G' {
				nums[1][rgb.g] = i
				rgb.g++
			} else {
				nums[2][rgb.b] = i
				rgb.b++
			}
			rgbIndices[i] = rgb
		}
		rgbSize = rgb
	}

	cnt := int64(0)
	for i, rgb := range rgbIndices {
		ci := s[i]
		if ci == 'R' {
			for ij := rgb.g; ij < rgbSize.g; ij++ {
				j := nums[1][ij]
				cnt += int64(rgbSize.b - rgbIndices[j].b)
			}
			for ij := rgb.b; ij < rgbSize.b; ij++ {
				j := nums[2][ij]
				cnt += int64(rgbSize.g - rgbIndices[j].g)
			}
		} else if ci == 'G' {
			for ij := rgb.b; ij < rgbSize.b; ij++ {
				j := nums[2][ij]
				cnt += int64(rgbSize.r - rgbIndices[j].r)
			}
			for ij := rgb.r; ij < rgbSize.r; ij++ {
				j := nums[0][ij]
				cnt += int64(rgbSize.b - rgbIndices[j].b)
			}
		} else {
			for ij := rgb.g; ij < rgbSize.g; ij++ {
				j := nums[1][ij]
				cnt += int64(rgbSize.r - rgbIndices[j].r)
			}
			for ij := rgb.r; ij < rgbSize.r; ij++ {
				j := nums[0][ij]
				cnt += int64(rgbSize.g - rgbIndices[j].g)
			}
		}
	}

	for i := 0; i <= n-3; i++ {
		ci := s[i]
		jMax := i + 1 + (n-i-3)/2
		for j := i + 1; j <= jMax; j++ {
			cj := s[j]
			if cj == ci {
				continue
			}
			k := 2*j - i
			ck := s[k]
			if ck != ci && ck != cj {
				cnt--
			}
		}
	}

	fmt.Println(cnt)
}

type rgbNums struct {
	r int
	g int
	b int
}

// util
// *   math/simple

func Abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func Min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow(base int, exponent uint) int {
	answer := 1
	for i := uint(0); i < exponent; i++ {
		answer *= base
	}
	return answer
}

func Gcd(big int, small int) int {
	rem := big % small
	if rem == 0 {
		return small
	}
	return Gcd(small, rem)
}

func Abs64(x int64) int64 {
	if x >= 0 {
		return x
	}
	return -x
}

func Min64(values ...int64) int64 {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max64(values ...int64) int64 {
	if len(values) == 0 {
		panic("no values")
	}
	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow64(base int64, exponent uint) int64 {
	answer := int64(1)
	for i := uint(0); i < exponent; i++ {
		answer *= base
	}
	return answer
}

// *   io

type Scanner struct {
	bufScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	return &Scanner{bufSc}
}

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}

func (sc *Scanner) ReadInt64() int64 {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.ParseInt(text, 10, 64)
	if err != nil {
		panic(err)
	}
	return num
}


Measured memory_bytes: 2004