from collections import defaultdict, Counter
from heapq import heapify, heappop, heappush
from sys import stdin


def main2():
    res = 0
    n = int(input())
    s = str(input())
    for i in range(n):
        for j in range(i+1, n):
            if s[i] == s[j]:
                continue
            else:
                for k in range(j+1, n):
                    if s[i] == s[k] or s[j] == s[k]:
                        continue
                    if j - i == k - j:
                        continue
                    res += 1
    print(res)


def main():
    res = 0
    n = int(input())
    s = str(input())
    r = [i for i in range(n) if s[i] == "R"]
    g = [i for i in range(n) if s[i] == "G"]
    b = [i for i in range(n) if s[i] == "B"]

    for i in range(n):
        if s[i] == "R":
            res += sum(x > i for x in g) * sum(x > i for x in b)
        elif s[i] == "G":
            res += sum(x > i for x in r) * sum(x > i for x in b)
        elif s[i] == "B":
            res += sum(x > i for x in r) * sum(x > i for x in g)
        for j in range(i+1, n):
            k = (j-i)+j
            if k >= n:
                continue
            if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
                res -= 1
    print(res)


def input(): return stdin.readline().rstrip()


main()
