import sys

import itertools

# import numpy as np

import time

import math



sys.setrecursionlimit(10 ** 7)



from collections import defaultdict



read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



n = int(readline())

s = eval(input())



counter = [(0, 0, 0)]

for c in s:

    rgb = counter[-1]

    r, g, b = 0, 0, 0

    if c == 'R':

        r = 1

    if c == 'G':

        g = 1

    if c == 'B':

        b = 1

    new_rgb = (rgb[0] + r, rgb[1] + g, rgb[2] + b)

    counter.append(new_rgb)



ans = 0

MAX = 4002

x = []

for i in range(1, min(len(s) + 1, MAX)):

    for j in range(i + 1, min(len(s) + 1, MAX)):

        if s[i - 1] == s[j - 1]:

            continue

        x.append((i, j))



y = []

for p in x:

    i = p[0]

    j = p[1]

    rgb = {'R', 'G', 'B'}

    sub = {s[i - 1], s[j - 1]}



    k_s = rgb.difference(sub).pop()

    k_idx = 0

    if k_s == 'R':

        k_idx = 0

    if k_s == 'G':

        k_idx = 1

    if k_s == 'B':

        k_idx = 2



    j_cnt = counter[j]

    k_cnt = counter[len(s)]

    omit = 0

    if (2 * j - i) <= len(s):

        omit = counter[2* j - i][k_idx] - counter[2 * j - i - 1][k_idx]

    ans += (k_cnt[k_idx] - j_cnt[k_idx] - omit)



print(ans)

import sys

import itertools

# import numpy as np

import time

import math



sys.setrecursionlimit(10 ** 7)



from collections import defaultdict



read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



n = int(readline())

s = eval(input())



r_c = 0

g_c = 0

b_c = 0

for c in s:

    if c == 'R':

        r_c += 1

    if c == 'G':

        g_c += 1

    if c == 'B':

        b_c += 1

rgb_count = r_c * g_c * b_c



MAX = min(len(s) + 1, 4005)

omit_count = 0

for i in range(1, len(s) + 1):

    for j in range(i + 1, len(s) + 1):

        k = 2 * j - i

        if k >= len(s) + 1:

            continue

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

            omit_count += 1

print((rgb_count - omit_count))
import sys
import itertools

# import numpy as np
import time
import math

sys.setrecursionlimit(10**7)
from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(readline())
s = eval(input())
counter = [(0, 0, 0)]
for c in s:
    rgb = counter[-1]
    r, g, b = 0, 0, 0
    if c == "R":
        r = 1
    if c == "G":
        g = 1
    if c == "B":
        b = 1
    new_rgb = (rgb[0] + r, rgb[1] + g, rgb[2] + b)
    counter.append(new_rgb)
ans = 0
MAX = 4002
x = []
for i in range(1, min(len(s) + 1, MAX)):
    for j in range(i + 1, min(len(s) + 1, MAX)):
        if s[i - 1] == s[j - 1]:
            continue
        x.append((i, j))
y = []
for p in x:
    i = p[0]
    j = p[1]
    rgb = {"R", "G", "B"}
    sub = {s[i - 1], s[j - 1]}
    k_s = rgb.difference(sub).pop()
    k_idx = 0
    if k_s == "R":
        k_idx = 0
    if k_s == "G":
        k_idx = 1
    if k_s == "B":
        k_idx = 2
    j_cnt = counter[j]
    k_cnt = counter[len(s)]
    omit = 0
    if (2 * j - i) <= len(s):
        omit = counter[2 * j - i][k_idx] - counter[2 * j - i - 1][k_idx]
    ans += k_cnt[k_idx] - j_cnt[k_idx] - omit
print(ans)

import sys
import itertools

# import numpy as np
import time
import math

sys.setrecursionlimit(10**7)
from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(readline())
s = eval(input())
r_c = 0
g_c = 0
b_c = 0
for c in s:
    if c == "R":
        r_c += 1
    if c == "G":
        g_c += 1
    if c == "B":
        b_c += 1
rgb_count = r_c * g_c * b_c
MAX = min(len(s) + 1, 4005)
omit_count = 0
for i in range(1, len(s) + 1):
    for j in range(i + 1, len(s) + 1):
        k = 2 * j - i
        if k >= len(s) + 1:
            continue
        if s[i - 1] != s[j - 1] and s[j - 1] != s[k - 1] and s[k - 1] != s[i - 1]:
            omit_count += 1
print((rgb_count - omit_count))

-counter = [(0, 0, 0)] +r_c = 0 +g_c = 0 +b_c = 0 -    rgb = counter[-1] -    r, g, b = 0, 0, 0 -        r = 1 +        r_c += 1 -        g = 1 +        g_c += 1 -        b = 1 -    new_rgb = (rgb[0] + r, rgb[1] + g, rgb[2] + b) -    counter.append(new_rgb) -ans = 0 -MAX = 4002 -x = [] -for i in range(1, min(len(s) + 1, MAX)): -    for j in range(i + 1, min(len(s) + 1, MAX)): -        if s[i - 1] == s[j - 1]: +        b_c += 1 +rgb_count = r_c * g_c * b_c +MAX = min(len(s) + 1, 4005) +omit_count = 0 +for i in range(1, len(s) + 1): +    for j in range(i + 1, len(s) + 1): +        k = 2 * j - i +        if k >= len(s) + 1: -        x.append((i, j)) -y = [] -for p in x: -    i = p[0] -    j = p[1] -    rgb = {"R", "G", "B"} -    sub = {s[i - 1], s[j - 1]} -    k_s = rgb.difference(sub).pop() -    k_idx = 0 -    if k_s == "R": -        k_idx = 0 -    if k_s == "G": -        k_idx = 1 -    if k_s == "B": -        k_idx = 2 -    j_cnt = counter[j] -    k_cnt = counter[len(s)] -    omit = 0 -    if (2 * j - i) <= len(s): -        omit = counter[2 * j - i][k_idx] - counter[2 * j - i - 1][k_idx] -    ans += k_cnt[k_idx] - j_cnt[k_idx] - omit -print(ans) +        if s[i - 1] != s[j - 1] and s[j - 1] != s[k - 1] and s[k - 1] != s[i - 1]: +            omit_count += 1 +print((rgb_count - omit_count))