import sys

import collections





def solve():

    readline = sys.stdin.buffer.readline

    mod = 10 ** 9 + 7

    n = int(readline())

    s = str(readline().rstrip().decode('utf-8'))

    c = collections.Counter(list(s))

    left = collections.defaultdict(int)

    cnt = 0

    for i in range(n - 2):

        left[s[i]] += 1

        mid = collections.defaultdict(int)

        for k, v in list(left.items()):

            mid[k] += v

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

            mid[s[j]] += 1

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

                if [s[i], s[j]].count("R") == 0:

                    cnt += c["R"] - mid["R"]

                    if j + j - i < n:

                        if s[j+j-i] == "R":

                            cnt -= 1

                elif [s[i], s[j]].count("G") == 0:

                    cnt += c["G"] - mid["G"]

                    if j + j - i < n:

                        if s[j+j-i] == "G":

                            cnt -= 1

                elif [s[i], s[j]].count("B") == 0:

                    cnt += c["B"] - mid["B"]

                    if j + j - i < n:

                        if s[j+j-i] == "B":

                            cnt -= 1

    print(cnt)





if __name__ == '__main__':

    solve()

import sys





def solve():

    readline = sys.stdin.buffer.readline

    mod = 10 ** 9 + 7

    n = int(readline())

    s = str(readline().rstrip().decode('utf-8'))

    r = s.count("R")

    g = s.count("G")

    b = s.count("B")

    cnt = r * g * b

    for i in range(n - 2):

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

            k = j + j - i

            if k < n:

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

                    cnt -= 1

    print(cnt)





if __name__ == '__main__':

    solve()

import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10**9 + 7
    n = int(readline())
    s = str(readline().rstrip().decode("utf-8"))
    c = collections.Counter(list(s))
    left = collections.defaultdict(int)
    cnt = 0
    for i in range(n - 2):
        left[s[i]] += 1
        mid = collections.defaultdict(int)
        for k, v in list(left.items()):
            mid[k] += v
        for j in range(i + 1, n - 1):
            mid[s[j]] += 1
            if s[i] != s[j]:
                if [s[i], s[j]].count("R") == 0:
                    cnt += c["R"] - mid["R"]
                    if j + j - i < n:
                        if s[j + j - i] == "R":
                            cnt -= 1
                elif [s[i], s[j]].count("G") == 0:
                    cnt += c["G"] - mid["G"]
                    if j + j - i < n:
                        if s[j + j - i] == "G":
                            cnt -= 1
                elif [s[i], s[j]].count("B") == 0:
                    cnt += c["B"] - mid["B"]
                    if j + j - i < n:
                        if s[j + j - i] == "B":
                            cnt -= 1
    print(cnt)


if __name__ == "__main__":
    solve()

import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10**9 + 7
    n = int(readline())
    s = str(readline().rstrip().decode("utf-8"))
    r = s.count("R")
    g = s.count("G")
    b = s.count("B")
    cnt = r * g * b
    for i in range(n - 2):
        for j in range(i + 1, n - 1):
            k = j + j - i
            if k < n:
                if s[i] != s[j] and s[j] != s[k] and s[i] != s[k]:
                    cnt -= 1
    print(cnt)


if __name__ == "__main__":
    solve()

-import collections -    c = collections.Counter(list(s)) -    left = collections.defaultdict(int) -    cnt = 0 +    r = s.count("R") +    g = s.count("G") +    b = s.count("B") +    cnt = r * g * b -        left[s[i]] += 1 -        mid = collections.defaultdict(int) -        for k, v in list(left.items()): -            mid[k] += v -            mid[s[j]] += 1 -            if s[i] != s[j]: -                if [s[i], s[j]].count("R") == 0: -                    cnt += c["R"] - mid["R"] -                    if j + j - i < n: -                        if s[j + j - i] == "R": -                            cnt -= 1 -                elif [s[i], s[j]].count("G") == 0: -                    cnt += c["G"] - mid["G"] -                    if j + j - i < n: -                        if s[j + j - i] == "G": -                            cnt -= 1 -                elif [s[i], s[j]].count("B") == 0: -                    cnt += c["B"] - mid["B"] -                    if j + j - i < n: -                        if s[j + j - i] == "B": -                            cnt -= 1 +            k = j + j - i +            if k < n: +                if s[i] != s[j] and s[j] != s[k] and s[i] != s[k]: +                    cnt -= 1