from itertools import permutations
n = int(input())
s = input()
s_num = []

for i in range(n):
    num = 0
    if s[i] == 'G':
        num = 1
    elif s[i] == 'B':
        num = 2
    s_num.append(num)
# R: 0, G: 1, B: 2

# RGB, RBG, GBR, GRB, BRG, BGR

indexs = [[], [], []]
for i, v in enumerate(s_num):
    indexs[v].append(i)

color_sum = [[len(indexs[0])], [len(indexs[1])], [len(indexs[2])]]
for i in range(n):
    for j in range(3):
        if s_num[i] == j:
            color_sum[j].append(color_sum[j][-1] - 1)
        else:
            color_sum[j].append(color_sum[j][-1])

ans = 0
for i, j, k in permutations([0, 1, 2]):
    for first in indexs[i]:
        for second in indexs[j]:
            if second < first:
                continue
            third_exp = second + (second - first)
            if third_exp < n:
                if s_num[third_exp] == k:
                    ans -= 1
            tmp = color_sum[k][second]
            ans += tmp
#             print(tmp, ans)
# print(color_sum)
print(ans)