package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	N := nextInt()
	S := next()

	// for test
	// N := 4000
	// S := "RRBRBRBRBRBGBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBBRRBRBRBRBRBGBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBBRRBRBRBRBRBGBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBBRRBRBRBRBRBGBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBBRRBRBRBRBRBGBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBBRRBRBRBRBRBGBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBBRRBRBRBRBRBGBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBBRRBRBRBRBRBGBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBBRRBRBRBRBRBGBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBBRRBRBRBRBRBGBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBBRRBRBRBRBRBGBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBBRRBRBRBRBRBGBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBBRRBRBRBRBRBGBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBBRRBRBRBRBRBGBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBBRRBRBRBRBRBGBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBBRRBRBRBRBRBGBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBBRRBRBRBRBRBGBRBGRBGGBBRRGBBRRRB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RBRBRBRBGBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBBRRBRBRBRBRBGBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB"

	// N := 39
	// S := "RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB"

	// N := 4
	// S := "RRGB"

	dp := make([]int, N)

	for i := 0; i < N-2; i++ {
		for j := i + 1; j < N-1; j++ {
			if S[i] == S[j] {
				continue
			}
			dp[i] += strings.Count(string(S[min(2*j-i+1, N):]), t(string(S[i]), string(S[j])))
			dp[i] += strings.Count(string(S[j+1:min(2*j-i, N)]), t(string(S[i]), string(S[j])))

			// for k := j + 1; k < N; k++ {
			// 	if j-i == k-j {
			// 		dp[i] += strings.Count(string(S[k+1:]), t(string(S[i]), string(S[j])))
			// 		break
			// 	}
			// 	if S[j] != S[k] && S[k] != S[i] {
			// 		dp[i]++
			// 	}
			// }
		}
	}

	sum := int64(0)
	for i := 0; i < N; i++ {
		sum += int64(dp[i])
	}
	fmt.Println(sum)

}

func min(a int, b int) int {
	if a < b {
		return a
	}
	return b
}

func t(s1 string, s2 string) string {
	if s1 == "R" {
		if s2 == "G" {
			return "B"
		}
		return "G"
	} else if s1 == "G" {
		if s2 == "R" {
			return "B"
		}
		return "R"
	}
	if s2 == "R" {
		return "G"
	}
	return "R"
}

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func split(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}

// -*-*-*-*-*-*-*-*-
// * tool snippets *
// -*-*-*-*-*-*-*-*-
func duplicate2Int(base [][]int) (ret [][]int) {
	ret = make([][]int, len(base))
	for i, v := range base {
		ret[i] = append([]int{}, v...)
	}
	return
}

// -*-*-*-*-*-*-*-*-*-*-*-*-*-
// * Algorithms Utility Zone *
// -*-*-*-*-*-*-*-*-*-*-*-*-*-

// -*-*-*-*-*-*-*-
// * 1. nibutan  *
// -*-*-*-*-*-*-*-
func lower_bound(arr []int, target int) int {
	l, r := 0, len(arr)
	for l < r {
		mid := (l + r) / 2
		if arr[mid] < target {
			l = mid + 1
		} else {
			r = mid
		}
	}
	return l
}

func upper_bound(arr []int, target int) int {
	l, r := 0, len(arr)
	for l < r {
		mid := (l + r) / 2
		if target < arr[mid] {
			r = mid
		} else {
			l = mid + 1
		}
	}
	return l
}

// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
// * math flavor typical theories *
// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
func gcd(a, b int) int {
	if a > b {
		return gcd(b, a)
	}
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

func pow(a, b int) (ret int) {
	ret = a
	// 10^2 = 100ってことは10に10を1回掛けることだね
	// なので初期値を含めると上限b-1未満
	for i := 0; i < b-1; i++ {
		ret *= a
	}
	return
}

func powMod(n, m, mod int) (ret int) {
	ret = 1
	for m > 0 {
		if m&1 == 1 {
			ret *= n
			ret %= mod
		}
		n *= n
		n %= mod
		m >>= 1
	}
	return ret
}


Measured memory_bytes: 1824