n = int(eval(input()))

s = eval(input())

s = s.replace('R', '0')

s = s.replace('G', '1')

s = s.replace('B', '2')



s0 = [0] * (n + 5)

s1 = [0] * (n + 5)

s2 = [0] * (n + 5)



for i in range(n):

    s0[i + 1] = s0[i] + (s[i] == '0')

    s1[i + 1] = s1[i] + (s[i] == '1')

    s2[i + 1] = s2[i] + (s[i] == '2')



#print(s0)

#print(s1)

#print(s2)



ans = 0

for i in range(n):

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

        if s[i] == s[j]: continue

        h = 99 - (ord(s[i]) + ord(s[j]))

        if h == 0:

            ans += s0[n] - s0[j]

            if 2 * j - i < n and s[2 * j - i] == '0': ans -= 1

        if h == 1:

            ans += s1[n] - s1[j]

            if 2 * j - i < n and s[2 * j - i] == '1': ans -= 1

        if h == 2:

            ans += s2[n] - s2[j]

            if 2 * j - i < n and s[2 * j - i] == '2': ans -= 1

        #print(i, j, h, ans)

print(ans)

n = int(eval(input()))

s = eval(input())

s = s.replace('R', '0') 

s = s.replace('G', '1')

s = s.replace('B', '2')



t = [[0] * (n + 5) for _ in range(3)]



for i in range(n):

    for j in range(3):

        t[j][i + 1] = t[j][i] + (s[i] == chr(48 + j))



ans = 0

for i in range(n):

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

        if s[i] == s[j]: continue

        h = 99 - (ord(s[i]) + ord(s[j]))

        ans += t[h][n] - t[h][j]

        if 2 * j - i < n and s[2 * j - i] == chr(48 + h): ans -= 1

print(ans)
n = int(eval(input()))
s = eval(input())
s = s.replace("R", "0")
s = s.replace("G", "1")
s = s.replace("B", "2")
s0 = [0] * (n + 5)
s1 = [0] * (n + 5)
s2 = [0] * (n + 5)
for i in range(n):
    s0[i + 1] = s0[i] + (s[i] == "0")
    s1[i + 1] = s1[i] + (s[i] == "1")
    s2[i + 1] = s2[i] + (s[i] == "2")
# print(s0)
# print(s1)
# print(s2)
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        if s[i] == s[j]:
            continue
        h = 99 - (ord(s[i]) + ord(s[j]))
        if h == 0:
            ans += s0[n] - s0[j]
            if 2 * j - i < n and s[2 * j - i] == "0":
                ans -= 1
        if h == 1:
            ans += s1[n] - s1[j]
            if 2 * j - i < n and s[2 * j - i] == "1":
                ans -= 1
        if h == 2:
            ans += s2[n] - s2[j]
            if 2 * j - i < n and s[2 * j - i] == "2":
                ans -= 1
        # print(i, j, h, ans)
print(ans)

n = int(eval(input()))
s = eval(input())
s = s.replace("R", "0")
s = s.replace("G", "1")
s = s.replace("B", "2")
t = [[0] * (n + 5) for _ in range(3)]
for i in range(n):
    for j in range(3):
        t[j][i + 1] = t[j][i] + (s[i] == chr(48 + j))
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        if s[i] == s[j]:
            continue
        h = 99 - (ord(s[i]) + ord(s[j]))
        ans += t[h][n] - t[h][j]
        if 2 * j - i < n and s[2 * j - i] == chr(48 + h):
            ans -= 1
print(ans)

-s0 = [0] * (n + 5) -s1 = [0] * (n + 5) -s2 = [0] * (n + 5) +t = [[0] * (n + 5) for _ in range(3)] -    s0[i + 1] = s0[i] + (s[i] == "0") -    s1[i + 1] = s1[i] + (s[i] == "1") -    s2[i + 1] = s2[i] + (s[i] == "2") -# print(s0) -# print(s1) -# print(s2) +    for j in range(3): +        t[j][i + 1] = t[j][i] + (s[i] == chr(48 + j)) -        if h == 0: -            ans += s0[n] - s0[j] -            if 2 * j - i < n and s[2 * j - i] == "0": -                ans -= 1 -        if h == 1: -            ans += s1[n] - s1[j] -            if 2 * j - i < n and s[2 * j - i] == "1": -                ans -= 1 -        if h == 2: -            ans += s2[n] - s2[j] -            if 2 * j - i < n and s[2 * j - i] == "2": -                ans -= 1 -        # print(i, j, h, ans) +        ans += t[h][n] - t[h][j] +        if 2 * j - i < n and s[2 * j - i] == chr(48 + h): +            ans -= 1