def count_bigger(a, b):

    i = j = 0

    c = []

    while i < len(a) and j < len(b):

        if a[i] >= b[j]:

            j += 1

            continue

        c.append(len(b) - j)

        i += 1

    if len(c) < len(a):

        c += [0] * (len(a) - len(c))

    for i in range(len(c) - 1, 0, -1):

        c[i - 1] += c[i]

    return c





def f(a, b, c):

    bc = count_bigger(b, c)

    i = j = ans = 0

    while i < len(a) and j < len(b):

        if a[i] >= b[j]:

            j += 1

            continue

        ans += bc[j] - len(set(c) & set(2 * _b - a[i] for _b in b[j:]))

        i += 1

    return ans





def solve(string):

    n, s = string.split()

    r, g, b = [], [], []

    for i, _s in enumerate(s):

        if _s == "R":

            r.append(i)

        if _s == "G":

            g.append(i)

        if _s == "B":

            b.append(i)

    return str(f(r, g, b) + f(r, b, g) + f(b, r, g) + f(b, g, r) + f(g, r, b) + f(g, b, r))





if __name__ == '__main__':

    import sys

    print((solve(sys.stdin.read().strip())))

from itertools import product





def solve(string):

    n, s = string.split()

    r, g, b = [], [], []

    r2, g2, b2 = set([]), set([]), set([])

    for i, _s in enumerate(s):

        if _s == "R":

            r.append(i)

            r2.add(2 * i)

        if _s == "G":

            g.append(i)

            g2.add(2 * i)

        if _s == "B":

            b.append(i)

            b2.add(2 * i)

    ans = len(r) * len(g) * len(b)

    for i, j in product(r, g):

        ans -= 1 if i + j in b2 else 0

    for i, j in product(g, b):

        ans -= 1 if i + j in r2 else 0

    for i, j in product(b, r):

        ans -= 1 if i + j in g2 else 0

    return str(ans)





if __name__ == '__main__':

    import sys

    print((solve(sys.stdin.read().strip())))

def count_bigger(a, b):
    i = j = 0
    c = []
    while i < len(a) and j < len(b):
        if a[i] >= b[j]:
            j += 1
            continue
        c.append(len(b) - j)
        i += 1
    if len(c) < len(a):
        c += [0] * (len(a) - len(c))
    for i in range(len(c) - 1, 0, -1):
        c[i - 1] += c[i]
    return c


def f(a, b, c):
    bc = count_bigger(b, c)
    i = j = ans = 0
    while i < len(a) and j < len(b):
        if a[i] >= b[j]:
            j += 1
            continue
        ans += bc[j] - len(set(c) & set(2 * _b - a[i] for _b in b[j:]))
        i += 1
    return ans


def solve(string):
    n, s = string.split()
    r, g, b = [], [], []
    for i, _s in enumerate(s):
        if _s == "R":
            r.append(i)
        if _s == "G":
            g.append(i)
        if _s == "B":
            b.append(i)
    return str(
        f(r, g, b) + f(r, b, g) + f(b, r, g) + f(b, g, r) + f(g, r, b) + f(g, b, r)
    )


if __name__ == "__main__":
    import sys

    print((solve(sys.stdin.read().strip())))

from itertools import product


def solve(string):
    n, s = string.split()
    r, g, b = [], [], []
    r2, g2, b2 = set([]), set([]), set([])
    for i, _s in enumerate(s):
        if _s == "R":
            r.append(i)
            r2.add(2 * i)
        if _s == "G":
            g.append(i)
            g2.add(2 * i)
        if _s == "B":
            b.append(i)
            b2.add(2 * i)
    ans = len(r) * len(g) * len(b)
    for i, j in product(r, g):
        ans -= 1 if i + j in b2 else 0
    for i, j in product(g, b):
        ans -= 1 if i + j in r2 else 0
    for i, j in product(b, r):
        ans -= 1 if i + j in g2 else 0
    return str(ans)


if __name__ == "__main__":
    import sys

    print((solve(sys.stdin.read().strip())))

-def count_bigger(a, b): -    i = j = 0 -    c = [] -    while i < len(a) and j < len(b): -        if a[i] >= b[j]: -            j += 1 -            continue -        c.append(len(b) - j) -        i += 1 -    if len(c) < len(a): -        c += [0] * (len(a) - len(c)) -    for i in range(len(c) - 1, 0, -1): -        c[i - 1] += c[i] -    return c - - -def f(a, b, c): -    bc = count_bigger(b, c) -    i = j = ans = 0 -    while i < len(a) and j < len(b): -        if a[i] >= b[j]: -            j += 1 -            continue -        ans += bc[j] - len(set(c) & set(2 * _b - a[i] for _b in b[j:])) -        i += 1 -    return ans +from itertools import product +    r2, g2, b2 = set([]), set([]), set([]) +            r2.add(2 * i) +            g2.add(2 * i) -    return str( -        f(r, g, b) + f(r, b, g) + f(b, r, g) + f(b, g, r) + f(g, r, b) + f(g, b, r) -    ) +            b2.add(2 * i) +    ans = len(r) * len(g) * len(b) +    for i, j in product(r, g): +        ans -= 1 if i + j in b2 else 0 +    for i, j in product(g, b): +        ans -= 1 if i + j in r2 else 0 +    for i, j in product(b, r): +        ans -= 1 if i + j in g2 else 0 +    return str(ans)