from collections import Counter,defaultdict,deque

from heapq import heappop,heappush,heapify

import sys,bisect,math,itertools,fractions,pprint

sys.setrecursionlimit(10**8)

mod = 10**9+7

INF = float('inf')

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))



n = inp()

s = eval(input())

ss = [0] * n

for i,t in enumerate(s):

    if t == 'R':

        ss[i] = 0

    elif t == 'G':

        ss[i] = 1

    else:

        ss[i] = 2

color = [[0] * 3 for _ in range(n)] 

color[0][ss[0]] = 1

for i,t in enumerate(ss):

    if i == 0:

        continue

    for j in range(3):

        if t == j:

            color[i][j] = color[i-1][j] + 1

        else:

            color[i][j] = color[i-1][j]

res = 0

for i in range(n-1):

    for j in range(i+1,n):

        if ss[i] == ss[j]:

            continue

        c = j-i

        yet = -1

        for _ in range(3):

            if ss[i] == _ or ss[j] == _ :

                continue

            yet = _

        res += color[-1][yet] - color[j][yet]

        if j+c < n and ss[j+c] == yet:

            res -= 1

print(res)

from collections import Counter,defaultdict,deque

from heapq import heappop,heappush,heapify

import sys,bisect,math,itertools,fractions,pprint

sys.setrecursionlimit(10**8)

mod = 10**9+7

INF = float('inf')

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))



n = inp()

s = eval(input())

r = s.count('R')

g = s.count('G')

b = s.count('B')

res = r*g*b

for i in range(n-1):

    for j in range(i+1,n):

        k = 2*j - i

        if k < n :

            if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:

                res -= 1

print(res)

from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools, fractions, pprint

sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")


def inp():
    return int(sys.stdin.readline())


def inpl():
    return list(map(int, sys.stdin.readline().split()))


n = inp()
s = eval(input())
ss = [0] * n
for i, t in enumerate(s):
    if t == "R":
        ss[i] = 0
    elif t == "G":
        ss[i] = 1
    else:
        ss[i] = 2
color = [[0] * 3 for _ in range(n)]
color[0][ss[0]] = 1
for i, t in enumerate(ss):
    if i == 0:
        continue
    for j in range(3):
        if t == j:
            color[i][j] = color[i - 1][j] + 1
        else:
            color[i][j] = color[i - 1][j]
res = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        if ss[i] == ss[j]:
            continue
        c = j - i
        yet = -1
        for _ in range(3):
            if ss[i] == _ or ss[j] == _:
                continue
            yet = _
        res += color[-1][yet] - color[j][yet]
        if j + c < n and ss[j + c] == yet:
            res -= 1
print(res)

from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools, fractions, pprint

sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")


def inp():
    return int(sys.stdin.readline())


def inpl():
    return list(map(int, sys.stdin.readline().split()))


n = inp()
s = eval(input())
r = s.count("R")
g = s.count("G")
b = s.count("B")
res = r * g * b
for i in range(n - 1):
    for j in range(i + 1, n):
        k = 2 * j - i
        if k < n:
            if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
                res -= 1
print(res)

-ss = [0] * n -for i, t in enumerate(s): -    if t == "R": -        ss[i] = 0 -    elif t == "G": -        ss[i] = 1 -    else: -        ss[i] = 2 -color = [[0] * 3 for _ in range(n)] -color[0][ss[0]] = 1 -for i, t in enumerate(ss): -    if i == 0: -        continue -    for j in range(3): -        if t == j: -            color[i][j] = color[i - 1][j] + 1 -        else: -            color[i][j] = color[i - 1][j] -res = 0 +r = s.count("R") +g = s.count("G") +b = s.count("B") +res = r * g * b -        if ss[i] == ss[j]: -            continue -        c = j - i -        yet = -1 -        for _ in range(3): -            if ss[i] == _ or ss[j] == _: -                continue -            yet = _ -        res += color[-1][yet] - color[j][yet] -        if j + c < n and ss[j + c] == yet: -            res -= 1 +        k = 2 * j - i +        if k < n: +            if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]: +                res -= 1